A not empty list containing only the given value.
toList ( singleton "a" ) == [ "a" ]Create a not empty list with n copies of a value.
Will always include at least 1 value.
toList ( repeat 4 "Value" ) == [ "Value", "Value", "Value", "Value" ]
toList ( repeat 0 "Test" ) == [ "Test" ]Create a list of numbers, every element increasing by one. You give the lowest and highest number that should be in the list.
Will always include the low value.
toList ( range 3 6 ) == [ 3, 4, 5, 6 ]
toList ( range 3 3 ) == [ 3 ]
toList ( range 6 3 ) == [ 6 ]A not empty list with the given head and tail
ls = withHead 5 [ 4, 3 ]
toList ls == [ 5, 4, 3 ]
head ls == 5
tail ls == [ 4, 3 ]Add an element to the front of a not empty list.
cons 1 ( singleton 2 ) == withHead 1 [ 2 ]
Convert a regular list into a not empty list, or Nothing if the list is empty
fromList [] == Nothing
fromList [ 1, 2, 3 ] == Just ( withHead 1 [ 2, 3 ] )Convert a not empty list into a regular list
toList ( withHead 1 [ 2, 3 ] ) == [ 1, 2, 3 ] toList ( singleton 1 ) == [ 1 ]
Deconstruct a not empty list into it's head and tail
unCons ( singleton 5 ) = ( 5, [] )
unCons ( withHead 1 [ 2, 3 ] ) = ( 1, [ 2, 3 ] )Extract the last element from a not empty list.
last ( withHead 1 [ 2, 3 ] ) == 3
last ( singleton 1 ) == 1Returns wether the list has a tail with elements
hasTail ( withHead 1 [ 2, 3 ] ) == True
hasTail ( singleton 1 ) == False
hasTail ( withHead 1 [] ) == FalseAppends a regular list to a not empty list
appendList ( singleton 1 ) [ 2, 3 ] == withHead 1 [ 2, 3 ]
appendList ( withHead 1 [ 2, 3 ] ) [ 4, 5 ] == withHead 1 [ 2, 3, 4, 5 ]Same as List.head but will always always return a value
Same as List.tail but will always return a value
tail ( withHead 1 [ 2, 3 ] ) == [ 2, 3 ]
tail ( singleton 1 ) == []Same as List.maximum but will always return a value
Same as List.minimum but will always return a value
Same as List.take but will always include the first element
take 2 ( withHead 1 [ 2, 3 ] ) == withHead 1 [ 2 ]
take 0 ( withHead 1 [ 2, 3 ] ) == singleton 1Same as List.drop but will always include the last element
drop 2 ( withHead 1 [ 2, 3 ] ) == withHead 2 [ 3 ]
drop 0 ( withHead 1 [ 2, 3 ] ) == singleton 3Same as List.filter but will return Nothing if no elements satisfy the test
filter isEven ( withHead 1 [ 2, 3, 4, 5, 6 ] ) == Just ( withHead 2 [ 4, 6 ] )
filter isEven ( withHead 1 [ 3, 5 ] ) == NothingSame as List.filterMap but will return Nothing if all elements return Nothing
numbers1 : Maybe ( List Int )
numbers1 =
filterMap String.toInt ( withHead "3" [ "hi", "12", "4th", "May" ] )
numbers2 : Maybe ( List Int )
numbers2 =
filterMap String.toInt ( withHead "hello" [ "world" ] )
-- numbers1 == Just [3, 12]
-- numbers2 == NothingSame as List.partition but will return a PartitionResult since either but not both lists could be empty.
Return type for NotEmpty.List.partition
Will be NoMatches when no elements in the list satisfy the test.
Will be OnlyMatches when all elements in the list satisfy the test.
Will be Both if there a both elements that do and don't satisfy the test.
The first list are the elements that satisfy the test and the second list are the elements that don't.
Same as List.length
Same as List.reverse
Same as List.member
Same as List.all
Same as List.any
Same as List.sum
Same as List.product
Same as List.map
Same as List.indexedMap
Same as List.foldl
Same as List.foldr
Same as List.append
Same as List.concat
Same as List.concatMap
Same as List.intersperse
Same as List.unzip
Same as List.sort
Same as List.sortBy
Same as List.sortWith
Same as List.map2
Same as List.map3
Same as List.map4
Same as List.map5
Not empty version of
List