Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/coreygirard/elm-nonemptylist exists but has no tag 1.0.0; Software Heritage has no tag 1.0.0 for it; no fork with the same repo name found; no cached copy. Use another version.
A library for a non-empty list type. More obscure/specialized functions are found under Extra.
Create a non-empty list containing just a single element
singleton 0Similar to List.repeat, except this is guaranteed to contain
at least one element, regardless of the integer provided. Otherwise
a Maybe return value would be required. If this behavior is desired,
use List.repeat plus fromList
repeat 3 "a" |> toList == [ "a", "a", "a" ]
repeat 0 "a" |> toList == [ "a" ]Works slightly differently from List.range. First provided number
will be the first number in the non-empty list, second provided number
will be the last number, and it can ascend or descend.
Equivalent to List.range a b when a<=b, equal to singleton a
if a>b
range 3 6 |> toList == [ 3, 4, 5, 6 ]
range 3 3 |> toList == [ 3 ]
range 6 3 |> toList == [ 6, 5, 4, 3 ]Create a non-empty list from an element and a list.
fromPair 0 [ 1, 2, 3 ] |> toList == [ 0, 1, 2, 3 ]Create a non-empty list from a tuple of element and list
fromTuple ( 0, [ 1, 2, 3 ] ) |> toList == [ 0, 1, 2, 3 ]Deconstruct a non-empty list into a tuple of element and list
fromTuple ( 0, [ 1, 2, 3 ] )
|> toTuple
== ( 0, [ 1, 2, 3 ] )Try to create a non-empty list from an ordinary list. Returns Nothing if input list is empty.
fromList [ 0, 1, 2 ] == Just (fromPair 0 [ 1, 2 ])
fromList [] == NothingConvert to a list
fromPair 0 [ 1, 2, 3 ] |> toList == [ 0, 1, 2, 3 ]Append a value to become the new last element.
append 4 [ 1, 2, 3 ]
|> toList
== [ 1, 2, 3, 4 ]Prepend a value to become the new first element.
prepend 0 [ 1, 2, 3 ]
|> toList
== [ 0, 1, 2, 3 ]Pop the first element.
popFirst 4 [ 1, 2, 3 ]
|> toList
== [ 1, 2, 3, 4 ]-> Maybe (a, ListNonempty a) -> (a, Maybe (ListNonempty a)) -> (a, Either (List a) (ListNonempty a))
Pop the last element.
popLast 4 [ 1, 2, 3 ]
|> toList
== [ 1, 2, 3, 4 ]-> Maybe (a, ListNonempty a) -> (a, Maybe (ListNonempty a)) -> (a, Either (List a) (ListNonempty a))
Equivalent to List.map
fromPair 0 [ 1, 2, 3 ]
|> map String.fromInt
|> toList
== [ "0", "1", "2", "3" ]Equivalent to List.indexedMap
fromPair "a" [ "b", "c", "d" ]
|> indexedMap Tuple.pair
|> toList
== [ ( 0, "a" ), ( 1, "b" ), ( 2, "c" ), ( 3, "d" ) ]Equivalent to List.foldl
fromPair 1 [ 2, 3 ] |> foldl (+) 0 == 6Equivalent to List.Extra.foldl1
fromPair 1 [ 2, 3 ] |> foldl (+) 0 == 6Equivalent to List.foldr
fromPair 1 [ 2, 3 ] |> foldr (+) 0 == 6Equivalent to List.Extra.foldr1
fromPair 1 [ 2, 3 ] |> foldr (+) 0 == 6Similar to List.filter. Returns List because we cannot guarantee
any elements will pass the test.
fromPair 1 [ 2, 3, 4 ] |> filter (\n -> n > 2) == [ 3, 4 ]
fromPair 1 [ 2, 3, 4 ] |> filter (\n -> n > 20) == []Similar to List.filterMap. Also returns List.
fromPair "3.5" [ "cat", "4", "ball" ]
|> filterMap String.toFloat
== [ 3.5, 4 ]Same as List.length
fromPair 0 [ 1, 2, 3 ] |> length == 4Whether a non-empty list has only a single element
fromPair 0 [ 1, 2, 3 ] |> isSingleton == False
fromPair 0 [] |> isSingleton == TrueSame as List.reverse.
fromPair 0 [ 1, 2, 3 ]
|> reverse
|> toList
== [ 3, 2, 1, 0 ]Same as List.member
fromPair 0 [ 1, 2, 3 ] |> member 2 == True
fromPair 0 [ 1, 2, 3 ] |> member 5 == FalseSame as List.all
fromPair 0 [ 1, 2, 3 ] |> all (\n -> n < 2) == False
fromPair 0 [ 1, 2, 3 ] |> all (\n -> n < 5) == TrueSame as List.any
fromPair 0 [ 1, 2, 3 ] |> any (\n -> n > 2) == True
fromPair 0 [ 1, 2, 3 ] |> any (\n -> n > 5) == FalseSimilar to List.maximum, but doesn't need to return a Maybe type
fromPair 0 [1, 2, 3] |> maximum == 3
fromPair 2 [] |> maximum == 2Similar to List.minimum, but doesn't need to return a Maybe type
fromPair 0 [1, 2, 3] |> minimum == 0
fromPair 2 [] |> minimum == 2Equivalent to List.sum
fromPair 1 [ 2, 3 ] |> sum == 6Equivalent to List.product
fromPair 1 [ 2, 3 ] |> product == 6Similar to List.append.
append (fromPair 0 [ 1, 2 ]) (fromPair 3 [ 4, 5 ])
|> toList
== [ 0, 1, 2, 3, 4, 5 ]Similar to List.concat
fromPair (fromPair 0 [ 1 ]) [ fromPair 2 [ 3 ] ]
|> concat
|> toList
== [ 0, 1, 2, 3 ]
fromPair (fromPair 0 []) []
|> concat
|> toList
== [ 0 ]Similar to List.concatMap
concatMap (\n -> fromPair n [ n ]) (fromPair 0 [ 1, 2 ])
|> toList
== [ 0, 0, 1, 1, 2, 2 ]Similar to List.map2
map2 (\a b -> a ++ "-" ++ b)
(fromPair "a" [ "b", "c" ])
(fromPair "1" [ "2", "3" ])
|> toList
== [ "a-1", "b-2", "c-3" ]Similar to List.map3
map3 (\a b c -> ( a, b, c ))
(fromPair 0 [ 1 ])
(fromPair 2 [ 3 ])
(fromPair 4 [ 5 ])
|> toList
== [ ( 0, 2, 4 ), ( 1, 3, 5 ) ]Similar to List.map4
map3 (\a b c -> ( a, b, c ))
(fromPair 0 [ 1 ])
(fromPair 2 [ 3 ])
(fromPair 4 [ 5 ])
|> toList
== [ ( 0, 2, 4 ), ( 1, 3, 5 ) ]Similar to List.map5
map3 (\a b c -> ( a, b, c ))
(fromPair 0 [ 1 ])
(fromPair 2 [ 3 ])
(fromPair 4 [ 5 ])
|> toList
== [ ( 0, 2, 4 ), ( 1, 3, 5 ) ]Similar to List.sort
fromPair 1 [ 3, 5, 0, 2, 4 ]
|> sort
|> toList
== [ 0, 1, 2, 3, 4, 5 ]Similar to List.sortBy
fromPair { x = 1, y = 1 } [ { x = 0, y = 2 }, { x = 2, y = 0 } ]
|> sortBy .x
|> toList
== [ { x = 0, y = 2 }, { x = 1, y = 1 }, { x = 2, y = 0 } ]
fromPair { x = 1, y = 1 } [ { x = 0, y = 2 }, { x = 2, y = 0 } ]
|> sortBy .y
|> toList
== [ { x = 2, y = 0 }, { x = 1, y = 1 }, { x = 0, y = 2 } ]Similar to List.sortWith
fromPair 0 [ 1, 2, 3, 4 ]
|> sortWith (\a b -> compare b a)
|> toList
== [ 4, 3, 2, 1, 0 ]Return the first element. Unlike List.head, doesn't need to return a Maybe.
fromPair 0 [ 1, 2, 3 ] |> head == 0Return everything except the first element. Unlike List.tail, doesn't need to return a Maybe.
fromPair 0 [ 1, 2, 3 ] |> tail == [ 1, 2, 3 ]Return everything except the last element. Doesn't need to return a Maybe.
fromPair 0 [ 1, 2, 3 ] |> rest == [ 0, 1, 2 ]Return the last element. Doesn't need to return a Maybe.
fromPair 0 [ 1, 2, 3 ] |> head == 3Equivalent to (\elems -> (head elems, tail elems))
fromPair 0 [ 1, 2, 3 ] |> uncons == ( 0, [ 1, 2, 3 ] )Equivalent to (\elems -> (rest elems, last elems))
fromPair 0 [ 1, 2, 3 ] |> unconsLast == ( [ 0, 1, 2 ], 3 )Return the first N elements. Always includes the first element, regardless of
the value of N. If this behavior is undesired, use toList and List.take
fromPair 0 [ 1, 2, 3 ] |> take 2 |> toList == [ 0, 1 ]
fromPair 0 [ 1, 2, 3 ] |> take 0 |> toList == [ 0 ]Return all elements except for the first N elements. Always includes the last element, regardless of
the value of N. If this behavior is undesired, use toList and List.drop
fromPair 0 [ 1, 2, 3 ] |> drop 2 |> toList == [ 2, 3 ]
fromPair 0 [ 1, 2, 3 ] |> drop 10 |> toList == [ 3 ]Return the last N elements. Always includes the last element, regardless of
the value of N. If this behavior is undesired, use toList >> List.reverse >> List.take n >> List.reverse
fromPair 0 [ 1, 2, 3 ] |> takeLast 2 |> toList == [ 2, 3 ]
fromPair 0 [ 1, 2, 3 ] |> takeLast 0 |> toList == [ 3 ]Return all elements except for the last N elements. Always includes the first element, regardless of
the value of N. If this behavior is undesired, use toList >> List.reverse >> List.drop n >> List.reverse
fromPair 0 [ 1, 2, 3 ] |> dropLast 2 |> toList == [ 2, 3 ]
fromPair 0 [ 1, 2, 3 ] |> dropLast 10 |> toList == [ 3 ]Similar to List.unzip.
fromPair ( "a", 1 ) [ ( "b", 2 ), ( "c", 3 ) ]
|> unzip2
== ( fromPair "a" [ "b", "c" ]
, fromPair 1 [ 2, 3 ]
)Similar to unzip2, but with 3-tuples.
fromPair ( 1, 2, 3 ) [ ( 4, 5, 6 ), ( 7, 8, 9 ) ]
|> unzip3
== ( fromPair 1 [ 4, 7 ]
, fromPair 2 [ 5, 8 ]
, fromPair 3 [ 6, 9 ]
)
A list type that must contain at least one element