List
Core
You can create a List with the [1,2,3] syntax, so lists are used all over the place. This module has a bunch of functions to help you work with them!
Types
FoldStep
type FoldStep a
= Continue a
| Stop aControl value for stoppableFoldl: keep going or halt with a final accumulator.
Examples
stoppableFoldl
(\n acc ->
if acc >= 3 then
Stop acc
else
Continue (acc + n)
)
0
[1, 1, 1, 1, 1]
== 3Values
map
map : (a -> b) -> List a -> List bApply a function to every element of a list.
Examples
map sqrt [1,4,9] == [1,2,3]
map not [True,False,True] == [False,True,False]So map func [ a, b, c ] is the same as [ func a, func b, func c ].
filter
filter : (a -> Bool) -> List a -> List aKeep elements that satisfy the test.
Examples
filter isEven [1,2,3,4,5,6] == [2,4,6]foldl
foldl : (a -> b -> b) -> b -> List a -> bReduce a list from the left.
Examples
foldl (+) 0 [1,2,3] == 6
foldl (::) [] [1,2,3] == [3,2,1]So foldl step state [1,2,3] is like saying:
state
|> step 1
|> step 2
|> step 3foldr
foldr : (a -> b -> b) -> b -> List a -> bReduce a list from the right.
Examples
foldr (+) 0 [1,2,3] == 6
foldr (::) [] [1,2,3] == [1,2,3]So foldr step state [1,2,3] is like saying:
state
|> step 3
|> step 2
|> step 1length
length : List a -> IntDetermine the length of a list.
Examples
length [1,2,3] == 3reverse
reverse : List a -> List aReverse a list.
Examples
reverse [1,2,3,4] == [4,3,2,1]member
member : a -> List a -> BoolFigure out whether a list contains a value.
Examples
member 9 [1,2,3,4] == False
member 4 [1,2,3,4] == Trueappend
append : List a -> List a -> List aPut two lists together.
Examples
append [1,1,2] [3,5,8] == [1,1,2,3,5,8]
append ['a','b'] ['c'] == ['a','b','c']You can also use the (++) operator to append lists.
concat
concat : List (List a) -> List aConcatenate a bunch of lists into a single list:
Examples
concat [[1,2],[3],[4,5]] == [1,2,3,4,5]concatMap
concatMap : (a -> List b) -> List a -> List bMap a given function onto a list and flatten the resulting lists.
Examples
concatMap f xs == concat (map f xs)intersperse
intersperse : a -> List a -> List aPlaces the given value between all members of the given list.
Examples
intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]partition
partition : (a -> Bool) -> List a -> (List a, List a)Partition a list based on some test. The first list contains all values that satisfy the test, and the second list contains all the values that do not.
Examples
partition (\x -> x < 3) [0,1,2,3,4,5] == ([0,1,2], [3,4,5])
partition isEven [0,1,2,3,4,5] == ([0,2,4], [1,3,5])map2
map2 : (a -> b -> c) -> List a -> List b -> List cCombine two lists, combining them with the given function. If one list is longer, the extra elements are dropped.
Examples
totals : List Int -> List Int -> List Int
totals xs ys =
List.map2 (+) xs ys
-- totals [1,2,3] [4,5,6] == [5,7,9]
pairs : List a -> List b -> List (a,b)
pairs xs ys =
List.map2 Tuple.pair xs ys
-- pairs ["alice","bob","chuck"] [2,5,7,8]
-- == [("alice",2),("bob",5),("chuck",7)]map3
map3 : (a -> b -> c -> result) -> List a -> List b -> List c -> List resultCombine three lists, combining them with the given function. If one list is longer, the extra elements are dropped.
Examples
map3 (\a b c -> a + b + c) [1,2] [3,4] [5,6] == [9,12]map4
map4 : (a -> b -> c -> d -> result) -> List a -> List b -> List c -> List d -> List resultCombine four lists, combining them with the given function. If one list is longer, the extra elements are dropped.
Examples
map4 (\a b c d -> a + b + c + d) [1] [2] [3] [4] == [10]map5
map5 : (a -> b -> c -> d -> e -> result) -> List a -> List b -> List c -> List d -> List e -> List resultCombine five lists, combining them with the given function. If one list is longer, the extra elements are dropped.
Examples
map5 (\a b c d e -> a + b + c + d + e) [1] [2] [3] [4] [5] == [15]indexedMap
indexedMap : (Int -> a -> b) -> List a -> List bSame as map but the function is also applied to the index of each element (starting at zero).
Examples
indexedMap Tuple.pair ["Tom","Sue","Bob"] == [ (0,"Tom"), (1,"Sue"), (2,"Bob") ]isEmpty
isEmpty : List a -> BoolDetermine if a list is empty.
Examples
isEmpty [] == True**Note:** It is usually preferable to use a case to test this so you do not forget to handle the (x :: xs) case as well!
head
head : List a -> Maybe aExtract the first element of a list.
Examples
head [1,2,3] == Just 1
head [] == Nothing**Note:** It is usually preferable to use a case to deconstruct a List because it gives you (x :: xs) and you can work with both subparts.
tail
tail : List a -> Maybe (List a)Extract the rest of the list.
Examples
tail [1,2,3] == Just [2,3]
tail [] == Nothing**Note:** It is usually preferable to use a case to deconstruct a List because it gives you (x :: xs) and you can work with both subparts.
take
take : Int -> List a -> List aTake the first *n* members of a list.
Examples
take 2 [1,2,3,4] == [1,2]drop
drop : Int -> List a -> List aDrop the first *n* members of a list.
Examples
drop 2 [1,2,3,4] == [3,4]singleton
singleton : a -> List aCreate a list with only one element:
Examples
singleton 1234 == [1234]
singleton "hi" == ["hi"]repeat
repeat : Int -> a -> List aCreate a list with *n* copies of a value:
Examples
repeat 3 (0,0) == [(0,0),(0,0),(0,0)]range
range : Int -> Int -> List IntCreate a list of numbers, every element increasing by one. You give the lowest and highest number that should be in the list.
Examples
range 3 6 == [3, 4, 5, 6]
range 3 3 == [3]
range 6 3 == []sort
sort : List comparable -> List comparableSort values from lowest to highest.
Examples
sort [3,1,5] == [1,3,5]sortBy
sortBy : (a -> comparable) -> List a -> List aSort values by a derived property.
Examples
alice = { name="Alice", height=1.62 }
bob = { name="Bob" , height=1.85 }
chuck = { name="Chuck", height=1.76 }
sortBy .name [chuck,alice,bob] == [alice,bob,chuck]
sortBy .height [chuck,alice,bob] == [alice,chuck,bob]
sortBy String.length ["mouse","cat"] == ["cat","mouse"]sortWith
sortWith : (a -> a -> Order) -> List a -> List aSort values with a custom comparison function.
Examples
sortWith flippedComparison [1,2,3,4,5] == [5,4,3,2,1]
flippedComparison a b =
case compare a b of
LT -> GT
EQ -> EQ
GT -> LTThis is also the most general sort function, allowing you to define any other: sort == sortWith compare.
maximum
maximum : List comparable -> Maybe comparableFind the maximum element in a non-empty list.
Examples
maximum [1,4,2] == Just 4
maximum [] == Nothingminimum
minimum : List comparable -> Maybe comparableFind the minimum element in a non-empty list.
Examples
minimum [3,2,1] == Just 1
minimum [] == Nothingsum
sum : List Int -> IntGet the sum of the list elements.
Examples
sum [1,2,3] == 6
sum [1,1,1] == 3
sum [] == 0product
product : List Int -> IntGet the product of the list elements.
Examples
product [2,2,2] == 8
product [3,3,3] == 27
product [] == 1any
any : (a -> Bool) -> List a -> BoolDetermine if any elements satisfy some test.
Examples
any isEven [2,3] == True
any isEven [1,3] == False
any isEven [] == Falseall
all : (a -> Bool) -> List a -> BoolDetermine if all elements satisfy some test.
Examples
all isEven [2,4] == True
all isEven [2,3] == False
all isEven [] == TruefilterMap
filterMap : (a -> Maybe b) -> List a -> List bFilter out certain values. For example, maybe you have a bunch of strings from an untrusted source and you want to turn them into numbers:
Examples
numbers : List Int
numbers =
filterMap String.toInt ["3", "hi", "12", "4th", "May"]
-- numbers == [3, 12]unzip
unzip : List (a, b) -> (List a, List b)Decompose a list of tuples into a tuple of lists.
Examples
unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])last
last : List a -> Maybe aExtract the last element of a list.
Examples
last [1,2,3] == Just 3
last [] == Nothinginit
init : List a -> Maybe (List a)Return all elements except the last one.
Examples
init [1,2,3] == Just [1,2]
init [] == NothinggetAt
getAt : Int -> List a -> Maybe aGet the element at an index, or Nothing if out of range.
Examples
getAt 1 [1,2,3] == Just 2
getAt 5 [1,2,3] == Nothinguncons
uncons : List a -> Maybe (a, List a)Decompose a non-empty list to its head and tail.
Examples
uncons [1,2,3] == Just (1, [2,3])
uncons [] == NothingunconsLast
unconsLast : List a -> Maybe (a, List a)Decompose a non-empty list to its last element and the rest.
Examples
unconsLast [1,2,3] == Just (3, [1,2])
unconsLast [] == NothingmaximumBy
maximumBy : (a -> comparable) -> List a -> Maybe aFind the maximum element after mapping to a comparable key.
Examples
maximumBy String.length ["a", "bbb", "cc"] == Just "bbb"
maximumBy identity [] == NothingmaximumWith
maximumWith : (a -> a -> Order) -> List a -> Maybe aFind the maximum element using a custom order.
Examples
maximumWith compare [1,4,2] == Just 4
maximumWith compare [] == NothingminimumBy
minimumBy : (a -> comparable) -> List a -> Maybe aFind the minimum element after mapping to a comparable key.
Examples
minimumBy String.length ["aaa", "b", "cc"] == Just "b"
minimumBy identity [] == NothingminimumWith
minimumWith : (a -> a -> Order) -> List a -> Maybe aFind the minimum element using a custom order.
Examples
minimumWith compare [3,1,2] == Just 1
minimumWith compare [] == NothingandMap
andMap : List a -> List (a -> b) -> List bMap a list of functions over a list of values (zipping).
Examples
andMap [1,2,3] [(\n -> n + 10), (\n -> n * 2), (\n -> n - 1)] == [11,4,2]andThen
andThen : (a -> List b) -> List a -> List bSame as concatMap.
Examples
andThen (\n -> [n, n]) [1,2] == [1,1,2,2]reverseMap
reverseMap : (a -> b) -> List a -> List bMap and reverse in one pass.
Examples
reverseMap (\n -> n * 2) [1,2,3] == [6,4,2]reverseFilter
reverseFilter : (a -> Bool) -> List a -> List aFilter and reverse in one pass.
Examples
reverseFilter (\n -> n > 1) [1,2,3] == [3,2]takeWhile
takeWhile : (a -> Bool) -> List a -> List aTake elements while the predicate holds.
Examples
takeWhile (\n -> n < 3) [1,2,3,4] == [1,2]dropWhile
dropWhile : (a -> Bool) -> List a -> List aDrop elements while the predicate holds.
Examples
dropWhile (\n -> n < 3) [1,2,3,4] == [3,4]unique
unique : List a -> List aRemove duplicate values, keeping first occurrences.
Examples
unique [1,1,2,3,2] == [1,2,3]uniqueBy
uniqueBy : (a -> b) -> List a -> List aRemove duplicates by a derived key.
Examples
uniqueBy String.length ["a", "b", "cc"] == ["a", "cc"]allDifferent
allDifferent : List a -> BoolTrue when every value appears once.
Examples
allDifferent [1,2,3] == True
allDifferent [1,1,2] == FalseallDifferentBy
allDifferentBy : (a -> b) -> List a -> BoolTrue when every derived key appears once.
Examples
allDifferentBy String.length ["a", "bb"] == True
allDifferentBy String.length ["a", "b"] == FalsesetIf
setIf : (a -> Bool) -> a -> List a -> List aReplace elements that match a predicate.
Examples
setIf (\n -> n > 2) 0 [1,2,3,4] == [1,2,0,0]setAt
setAt : Int -> a -> List a -> List aReplace the element at an index.
Examples
setAt 1 9 [1,2,3] == [1,9,3]remove
remove : a -> List a -> List aRemove the first occurrence of a value.
Examples
remove 2 [1,2,3,2] == [1,3,2]updateIf
updateIf : (a -> Bool) -> (a -> a) -> List a -> List aUpdate elements that match a predicate.
Examples
updateIf (\n -> n > 2) (\n -> n * 10) [1,2,3] == [1,2,30]updateAt
updateAt : Int -> (a -> a) -> List a -> List aUpdate the element at an index.
Examples
updateAt 1 (\n -> n * 10) [1,2,3] == [1,20,3]updateIfIndex
updateIfIndex : (Int -> Bool) -> (a -> a) -> List a -> List aUpdate elements whose index matches.
Examples
updateIfIndex (\i -> i == 0) (\n -> n + 10) [1,2,3] == [11,2,3]removeAt
removeAt : Int -> List a -> List aRemove the element at an index.
Examples
removeAt 1 [1,2,3] == [1,3]removeIfIndex
removeIfIndex : (Int -> Bool) -> List a -> List aRemove elements whose index matches.
Examples
removeIfIndex (\i -> i == 1) [1,2,3] == [1,3]filterNot
filterNot : (a -> Bool) -> List a -> List aKeep elements that fail the predicate.
Examples
filterNot (\n -> n > 2) [1,2,3,4] == [1,2]swapAt
swapAt : Int -> Int -> List a -> List aSwap the elements at two indices.
Examples
swapAt 0 2 [1,2,3] == [3,2,1]stableSortWith
stableSortWith : (a -> a -> Order) -> List a -> List aStable sort with a custom comparison.
Examples
stableSortWith compare [3,1,2] == [1,2,3]intercalate
intercalate : List a -> List (List a) -> List aInsert a separator list between list segments and flatten.
Examples
intercalate [0] [[1,2],[3],[4]] == [1,2,0,3,0,4]transpose
transpose : List (List a) -> List (List a)Transpose rows and columns.
Examples
transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]]subsequences
subsequences : List a -> List (List a)All subsequences, including the empty list.
Examples
subsequences [1,2] == [[],[1],[1,2],[2]]permutations
permutations : List a -> List (List a)All permutations of a list.
Examples
permutations [1,2] == [[1,2],[2,1]]interweave
interweave : List a -> List a -> List aInterleave two lists.
Examples
interweave [1,2,3] [8,9] == [1,8,2,9,3]cartesianProduct
cartesianProduct : List (List a) -> List (List a)Cartesian product of a list of lists.
Examples
cartesianProduct [[1,2],[3]] == [[1,3],[2,3]]uniquePairs
uniquePairs : List a -> List (a, a)All unordered pairs of distinct positions.
Examples
uniquePairs [1,2,3] == [(1,2),(1,3),(2,3)]foldl1
foldl1 : (a -> a -> a) -> List a -> Maybe aLeft fold without a starting value.
Examples
foldl1 (+) [1,2,3] == Just 6
foldl1 (+) [] == Nothingfoldr1
foldr1 : (a -> a -> a) -> List a -> Maybe aRight fold without a starting value.
Examples
foldr1 max [1,3,2] == Just 3
foldr1 (+) [] == NothingindexedFoldl
indexedFoldl : (Int -> a -> b -> b) -> b -> List a -> bLeft fold with element indices.
Examples
indexedFoldl (\i x acc -> acc + i * x) 0 [1,2,3] == 8indexedFoldr
indexedFoldr : (Int -> a -> b -> b) -> b -> List a -> bRight fold with element indices.
Examples
indexedFoldr (\i x acc -> (i, x) :: acc) [] ["a","b"] == [(0,"a"),(1,"b")]stoppableFoldl
stoppableFoldl : (a -> b -> FoldStep b) -> b -> List a -> bLeft fold that can stop early via FoldStep.
Examples
stoppableFoldl
(\n acc ->
if n < 0 then
Stop acc
else
Continue (acc + n)
)
0
[1, 2, -9, 4]
== 3scanl
scanl : (a -> b -> b) -> b -> List a -> List bLeft scan of intermediate fold values.
Examples
scanl (+) 0 [1,2,3] == [0,1,3,6]scanl1
scanl1 : (a -> a -> a) -> List a -> List aLeft scan without a starting value.
Examples
scanl1 (+) [1,2,3] == [1,3,6]scanr
scanr : (a -> b -> b) -> b -> List a -> List bRight scan of intermediate fold values.
Examples
scanr (+) 0 [1,2,3] == [6,5,3,0]scanr1
scanr1 : (a -> a -> a) -> List a -> List aRight scan without a starting value.
Examples
scanr1 (+) [1,2,3] == [6,5,3]mapAccuml
mapAccuml : (a -> b -> (a, c)) -> a -> List b -> (a, List c)Map while threading an accumulator left to right.
Examples
mapAccuml (\acc x -> (acc + x, acc)) 0 [1,2,3] == (6, [0,1,3])mapAccumr
mapAccumr : (a -> b -> (a, c)) -> a -> List b -> (a, List c)Map while threading an accumulator right to left.
Examples
mapAccumr (\acc x -> (acc + x, acc)) 0 [1,2,3] == (6, [5,3,0])unfoldr
unfoldr : (b -> Maybe (a, b)) -> b -> List aBuild a list by unfolding a seed.
Examples
unfoldr (\n -> if n == 0 then Nothing else Just (n, n - 1)) 3 == [3,2,1]iterate
iterate : (a -> Maybe a) -> a -> List aRepeatedly apply a function until Nothing.
Examples
iterate (\n -> if n >= 3 then Nothing else Just (n + 1)) 1 == [1,2,3]initialize
initialize : Int -> (Int -> a) -> List aBuild a list of length n from an index function.
Examples
initialize 3 identity == [0,1,2]cycle
cycle : Int -> List a -> List aTake n elements by cycling a list.
Examples
cycle 5 [1,2] == [1,2,1,2,1]reverseRange
reverseRange : Int -> Int -> List IntInclusive descending integer range.
Examples
reverseRange 3 1 == [3,2,1]
reverseRange 1 3 == []splitAt
splitAt : Int -> List a -> (List a, List a)Split a list at an index.
Examples
splitAt 2 [1,2,3,4] == ([1,2], [3,4])splitWhen
splitWhen : (a -> Bool) -> List a -> Maybe (List a, List a)Split before the first matching element.
Examples
splitWhen (\n -> n > 2) [1,2,3,4] == Just ([1,2], [3,4])
splitWhen (\n -> n > 9) [1,2] == NothingtakeWhileRight
takeWhileRight : (a -> Bool) -> List a -> List aTake a suffix while the predicate holds.
Examples
takeWhileRight (\n -> n > 2) [1,2,3,4] == [3,4]dropWhileRight
dropWhileRight : (a -> Bool) -> List a -> List aDrop a suffix while the predicate holds.
Examples
dropWhileRight (\n -> n > 2) [1,2,3,4] == [1,2]span
span : (a -> Bool) -> List a -> (List a, List a)Split into longest matching prefix and the rest.
Examples
span (\n -> n < 3) [1,2,3,4] == ([1,2], [3,4])break
break : (a -> Bool) -> List a -> (List a, List a)Split before the first element that matches.
Examples
break (\n -> n > 2) [1,2,3,4] == ([1,2], [3,4])stripPrefix
stripPrefix : List a -> List a -> Maybe (List a)Remove a prefix when present.
Examples
stripPrefix [1,2] [1,2,3] == Just [3]
stripPrefix [9] [1,2,3] == Nothinggroup
group : List a -> List (a, List a)Group adjacent equal elements.
Examples
group [1,1,2,2,2,3] == [(1,[1]),(2,[2,2]),(3,[])]groupWhile
groupWhile : (a -> a -> Bool) -> List a -> List (a, List a)Group adjacent elements with a relation.
Examples
groupWhile (\a b -> a == b) [1,1,2,3,3] == [(1,[1]),(2,[]),(3,[3])]inits
inits : List a -> List (List a)All prefixes of a list.
Examples
inits [1,2,3] == [[],[1],[1,2],[1,2,3]]tails
tails : List a -> List (List a)All suffixes of a list.
Examples
tails [1,2,3] == [[1,2,3],[2,3],[3],[]]select
select : List a -> List (a, List a)Each element paired with the list without it.
Examples
select [1,2,3] == [(1,[2,3]),(2,[1,3]),(3,[1,2])]selectSplit
selectSplit : List a -> List (List a, a, List a)Each element with the parts before and after it.
Examples
selectSplit [1,2,3] == [([],1,[2,3]),([1],2,[3]),([1,2],3,[])]gatherEquals
gatherEquals : List a -> List (a, List a)Gather equal elements (not only adjacent).
Examples
gatherEquals [1,2,1,3,2] == [(1,[1]),(2,[2]),(3,[])]gatherEqualsBy
gatherEqualsBy : (a -> b) -> List a -> List (a, List a)Gather by a derived key.
Examples
gatherEqualsBy String.length ["a","bb","c","dd"]
== [("a",["c"]),("bb",["dd"])]gatherWith
gatherWith : (a -> a -> Bool) -> List a -> List (a, List a)Gather with a custom equality.
Examples
gatherWith (\a b -> a == b) [1,2,1] == [(1,[1]),(2,[])]subsequencesNonEmpty
subsequencesNonEmpty : List a -> List (a, List a)Non-empty subsequences as head plus rest.
Examples
subsequencesNonEmpty [1,2] == [(1,[]),(1,[2]),(2,[])]frequencies
frequencies : List comparable -> List (comparable, Int)Count occurrences of each comparable value.
Examples
frequencies [1,2,1,3,1] == [(1,3),(2,1),(3,1)]isPrefixOf
isPrefixOf : List a -> List a -> BoolTrue when the first list is a prefix of the second.
Examples
isPrefixOf [1,2] [1,2,3] == True
isPrefixOf [2,3] [1,2,3] == FalseisSuffixOf
isSuffixOf : List a -> List a -> BoolTrue when the first list is a suffix of the second.
Examples
isSuffixOf [2,3] [1,2,3] == True
isSuffixOf [1,2] [1,2,3] == FalseisInfixOf
isInfixOf : List a -> List a -> BoolTrue when the first list is a contiguous infix.
Examples
isInfixOf [2,3] [1,2,3,4] == True
isInfixOf [1,3] [1,2,3] == FalseisSubsequenceOf
isSubsequenceOf : List a -> List a -> BoolTrue when the first list is a subsequence.
Examples
isSubsequenceOf [1,3] [1,2,3] == True
isSubsequenceOf [3,1] [1,2,3] == FalseisPermutationOf
isPermutationOf : List a -> List a -> BoolTrue when the lists are permutations of each other.
Examples
isPermutationOf [1,2,3] [3,1,2] == True
isPermutationOf [1,2] [1,2,2] == FalsenotMember
notMember : a -> List a -> BoolTrue when a value is not in the list.
Examples
notMember 9 [1,2,3] == True
notMember 2 [1,2,3] == Falsefind
find : (a -> Bool) -> List a -> Maybe aFirst element that matches a predicate.
Examples
find (\n -> n > 2) [1,2,3,4] == Just 3
find (\n -> n > 9) [1,2] == NothingelemIndex
elemIndex : a -> List a -> Maybe IntIndex of the first matching value.
Examples
elemIndex 2 [1,2,3,2] == Just 1
elemIndex 9 [1,2,3] == NothingelemIndices
elemIndices : a -> List a -> List IntAll indices of a value.
Examples
elemIndices 2 [1,2,3,2] == [1,3]findIndex
findIndex : (a -> Bool) -> List a -> Maybe IntIndex of the first matching predicate.
Examples
findIndex (\n -> n > 2) [1,2,3,4] == Just 2findIndices
findIndices : (a -> Bool) -> List a -> List IntAll indices matching a predicate.
Examples
findIndices (\n -> n > 2) [1,2,3,4] == [2,3]findMap
findMap : (a -> Maybe b) -> List a -> Maybe bFirst successful Maybe from mapping.
Examples
findMap String.toInt ["a","12","b"] == Just 12
findMap String.toInt ["a","b"] == Nothingcount
count : (a -> Bool) -> List a -> IntCount elements that match a predicate.
Examples
count (\n -> n > 2) [1,2,3,4] == 2zip
zip : List a -> List b -> List (a, b)Zip two lists into pairs.
Examples
zip [1,2,3] ["a","b"] == [(1,"a"),(2,"b")]zip3
zip3 : List a -> List b -> List c -> List (a, b, c)Zip three lists into triples.
Examples
zip3 [1,2] ["a","b"] [True,False] == [(1,"a",True),(2,"b",False)]lift2
lift2 : (a -> b -> c) -> List a -> List b -> List cApply a function to every pair from two lists.
Examples
lift2 Tuple.pair [1,2] ["a","b"] == [(1,"a"),(1,"b"),(2,"a"),(2,"b")]lift3
lift3 : (a -> b -> c -> d) -> List a -> List b -> List c -> List dApply a function to every triple from three lists.
Examples
lift3 (\a b c -> (a,b,c)) [1] [2] [3] == [(1,2,3)]lift4
lift4 : (a -> b -> c -> d -> e) -> List a -> List b -> List c -> List d -> List eApply a function to every quadruple from four lists.
Examples
lift4 (\a b c d -> a + b + c + d) [1] [2] [3] [4] == [10]groupsOf
groupsOf : Int -> List a -> List (List a)Split into non-overlapping groups of a given size.
Examples
groupsOf 2 [1,2,3,4,5] == [[1,2],[3,4]]groupsOfWithStep
groupsOfWithStep : Int -> Int -> List a -> List (List a)Split into groups with a custom step.
Examples
groupsOfWithStep 2 1 [1,2,3,4] == [[1,2],[2,3],[3,4]]groupsOfVarying
groupsOfVarying : List Int -> List a -> List (List a)Split into groups of varying sizes.
Examples
groupsOfVarying [1,2] [1,2,3,4] == [[1],[2,3]]greedyGroupsOf
greedyGroupsOf : Int -> List a -> List (List a)Like groupsOf, keeping a short final group.
Examples
greedyGroupsOf 2 [1,2,3,4,5] == [[1,2],[3,4],[5]]greedyGroupsOfWithStep
greedyGroupsOfWithStep : Int -> Int -> List a -> List (List a)Like groupsOfWithStep, keeping a short final group.
Examples
greedyGroupsOfWithStep 2 3 [1,2,3,4,5] == [[1,2],[4,5]]joinOn
joinOn : (a -> b -> c) -> (a -> comparable) -> (b -> comparable) -> List a -> List b -> List cInner join two lists on comparable keys.
Examples
joinOn Tuple.pair .id .owner
[{id=1},{id=2}]
[{owner=1,name="a"},{owner=1,name="b"}]
== [({id=1},{owner=1,name="a"}),({id=1},{owner=1,name="b"})]