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 a

Control 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]
    == 3

Values

map

map : (a -> b) -> List a -> List b

Apply 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 a

Keep 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 -> b

Reduce 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 3

foldr

foldr : (a -> b -> b) -> b -> List a -> b

Reduce 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 1

length

length : List a -> Int

Determine the length of a list.

Examples

length [1,2,3] == 3

reverse

reverse : List a -> List a

Reverse a list.

Examples

reverse [1,2,3,4] == [4,3,2,1]

member

member : a -> List a -> Bool

Figure out whether a list contains a value.

Examples

member 9 [1,2,3,4] == False
member 4 [1,2,3,4] == True

append

append : List a -> List a -> List a

Put 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 a

Concatenate 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 b

Map 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 a

Places 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 c

Combine 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 result

Combine 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 result

Combine 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 result

Combine 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 b

Same 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 -> Bool

Determine 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!

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 a

Take the first *n* members of a list.

Examples

take 2 [1,2,3,4] == [1,2]

drop

drop : Int -> List a -> List a

Drop the first *n* members of a list.

Examples

drop 2 [1,2,3,4] == [3,4]

singleton

singleton : a -> List a

Create a list with only one element:

Examples

singleton 1234 == [1234]
singleton "hi" == ["hi"]

repeat

repeat : Int -> a -> List a

Create a list with *n* copies of a value:

Examples

repeat 3 (0,0) == [(0,0),(0,0),(0,0)]

range

range : Int -> Int -> List Int

Create 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 comparable

Sort values from lowest to highest.

Examples

sort [3,1,5] == [1,3,5]

sortBy

sortBy : (a -> comparable) -> List a -> List a

Sort 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 a

Sort 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 -> LT

This is also the most general sort function, allowing you to define any other: sort == sortWith compare.

maximum

maximum : List comparable -> Maybe comparable

Find the maximum element in a non-empty list.

Examples

maximum [1,4,2] == Just 4
maximum [] == Nothing

minimum

minimum : List comparable -> Maybe comparable

Find the minimum element in a non-empty list.

Examples

minimum [3,2,1] == Just 1
minimum [] == Nothing

sum

sum : List Int -> Int

Get the sum of the list elements.

Examples

sum [1,2,3] == 6
sum [1,1,1] == 3
sum [] == 0

product

product : List Int -> Int

Get the product of the list elements.

Examples

product [2,2,2] == 8
product [3,3,3] == 27
product [] == 1

any

any : (a -> Bool) -> List a -> Bool

Determine if any elements satisfy some test.

Examples

any isEven [2,3] == True
any isEven [1,3] == False
any isEven [] == False

all

all : (a -> Bool) -> List a -> Bool

Determine if all elements satisfy some test.

Examples

all isEven [2,4] == True
all isEven [2,3] == False
all isEven [] == True

filterMap

filterMap : (a -> Maybe b) -> List a -> List b

Filter 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 a

Extract the last element of a list.

Examples

last [1,2,3] == Just 3
last [] == Nothing

init

init : List a -> Maybe (List a)

Return all elements except the last one.

Examples

init [1,2,3] == Just [1,2]
init [] == Nothing

getAt

getAt : Int -> List a -> Maybe a

Get the element at an index, or Nothing if out of range.

Examples

getAt 1 [1,2,3] == Just 2
getAt 5 [1,2,3] == Nothing

uncons

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 [] == Nothing

unconsLast

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 [] == Nothing

maximumBy

maximumBy : (a -> comparable) -> List a -> Maybe a

Find the maximum element after mapping to a comparable key.

Examples

maximumBy String.length ["a", "bbb", "cc"] == Just "bbb"
maximumBy identity [] == Nothing

maximumWith

maximumWith : (a -> a -> Order) -> List a -> Maybe a

Find the maximum element using a custom order.

Examples

maximumWith compare [1,4,2] == Just 4
maximumWith compare [] == Nothing

minimumBy

minimumBy : (a -> comparable) -> List a -> Maybe a

Find the minimum element after mapping to a comparable key.

Examples

minimumBy String.length ["aaa", "b", "cc"] == Just "b"
minimumBy identity [] == Nothing

minimumWith

minimumWith : (a -> a -> Order) -> List a -> Maybe a

Find the minimum element using a custom order.

Examples

minimumWith compare [3,1,2] == Just 1
minimumWith compare [] == Nothing

andMap

andMap : List a -> List (a -> b) -> List b

Map 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 b

Same as concatMap.

Examples

andThen (\n -> [n, n]) [1,2] == [1,1,2,2]

reverseMap

reverseMap : (a -> b) -> List a -> List b

Map and reverse in one pass.

Examples

reverseMap (\n -> n * 2) [1,2,3] == [6,4,2]

reverseFilter

reverseFilter : (a -> Bool) -> List a -> List a

Filter and reverse in one pass.

Examples

reverseFilter (\n -> n > 1) [1,2,3] == [3,2]

takeWhile

takeWhile : (a -> Bool) -> List a -> List a

Take elements while the predicate holds.

Examples

takeWhile (\n -> n < 3) [1,2,3,4] == [1,2]

dropWhile

dropWhile : (a -> Bool) -> List a -> List a

Drop elements while the predicate holds.

Examples

dropWhile (\n -> n < 3) [1,2,3,4] == [3,4]

unique

unique : List a -> List a

Remove duplicate values, keeping first occurrences.

Examples

unique [1,1,2,3,2] == [1,2,3]

uniqueBy

uniqueBy : (a -> b) -> List a -> List a

Remove duplicates by a derived key.

Examples

uniqueBy String.length ["a", "b", "cc"] == ["a", "cc"]

allDifferent

allDifferent : List a -> Bool

True when every value appears once.

Examples

allDifferent [1,2,3] == True
allDifferent [1,1,2] == False

allDifferentBy

allDifferentBy : (a -> b) -> List a -> Bool

True when every derived key appears once.

Examples

allDifferentBy String.length ["a", "bb"] == True
allDifferentBy String.length ["a", "b"] == False

setIf

setIf : (a -> Bool) -> a -> List a -> List a

Replace 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 a

Replace the element at an index.

Examples

setAt 1 9 [1,2,3] == [1,9,3]

remove

remove : a -> List a -> List a

Remove 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 a

Update 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 a

Update 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 a

Update elements whose index matches.

Examples

updateIfIndex (\i -> i == 0) (\n -> n + 10) [1,2,3] == [11,2,3]

removeAt

removeAt : Int -> List a -> List a

Remove the element at an index.

Examples

removeAt 1 [1,2,3] == [1,3]

removeIfIndex

removeIfIndex : (Int -> Bool) -> List a -> List a

Remove elements whose index matches.

Examples

removeIfIndex (\i -> i == 1) [1,2,3] == [1,3]

filterNot

filterNot : (a -> Bool) -> List a -> List a

Keep elements that fail the predicate.

Examples

filterNot (\n -> n > 2) [1,2,3,4] == [1,2]

swapAt

swapAt : Int -> Int -> List a -> List a

Swap the elements at two indices.

Examples

swapAt 0 2 [1,2,3] == [3,2,1]

stableSortWith

stableSortWith : (a -> a -> Order) -> List a -> List a

Stable sort with a custom comparison.

Examples

stableSortWith compare [3,1,2] == [1,2,3]

intercalate

intercalate : List a -> List (List a) -> List a

Insert 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 a

Interleave 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 a

Left fold without a starting value.

Examples

foldl1 (+) [1,2,3] == Just 6
foldl1 (+) [] == Nothing

foldr1

foldr1 : (a -> a -> a) -> List a -> Maybe a

Right fold without a starting value.

Examples

foldr1 max [1,3,2] == Just 3
foldr1 (+) [] == Nothing

indexedFoldl

indexedFoldl : (Int -> a -> b -> b) -> b -> List a -> b

Left fold with element indices.

Examples

indexedFoldl (\i x acc -> acc + i * x) 0 [1,2,3] == 8

indexedFoldr

indexedFoldr : (Int -> a -> b -> b) -> b -> List a -> b

Right 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 -> b

Left 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]
    == 3

scanl

scanl : (a -> b -> b) -> b -> List a -> List b

Left scan of intermediate fold values.

Examples

scanl (+) 0 [1,2,3] == [0,1,3,6]

scanl1

scanl1 : (a -> a -> a) -> List a -> List a

Left scan without a starting value.

Examples

scanl1 (+) [1,2,3] == [1,3,6]

scanr

scanr : (a -> b -> b) -> b -> List a -> List b

Right scan of intermediate fold values.

Examples

scanr (+) 0 [1,2,3] == [6,5,3,0]

scanr1

scanr1 : (a -> a -> a) -> List a -> List a

Right 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 a

Build 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 a

Repeatedly 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 a

Build a list of length n from an index function.

Examples

initialize 3 identity == [0,1,2]

cycle

cycle : Int -> List a -> List a

Take n elements by cycling a list.

Examples

cycle 5 [1,2] == [1,2,1,2,1]

reverseRange

reverseRange : Int -> Int -> List Int

Inclusive 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] == Nothing

takeWhileRight

takeWhileRight : (a -> Bool) -> List a -> List a

Take a suffix while the predicate holds.

Examples

takeWhileRight (\n -> n > 2) [1,2,3,4] == [3,4]

dropWhileRight

dropWhileRight : (a -> Bool) -> List a -> List a

Drop 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] == Nothing

group

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 -> Bool

True when the first list is a prefix of the second.

Examples

isPrefixOf [1,2] [1,2,3] == True
isPrefixOf [2,3] [1,2,3] == False

isSuffixOf

isSuffixOf : List a -> List a -> Bool

True when the first list is a suffix of the second.

Examples

isSuffixOf [2,3] [1,2,3] == True
isSuffixOf [1,2] [1,2,3] == False

isInfixOf

isInfixOf : List a -> List a -> Bool

True when the first list is a contiguous infix.

Examples

isInfixOf [2,3] [1,2,3,4] == True
isInfixOf [1,3] [1,2,3] == False

isSubsequenceOf

isSubsequenceOf : List a -> List a -> Bool

True when the first list is a subsequence.

Examples

isSubsequenceOf [1,3] [1,2,3] == True
isSubsequenceOf [3,1] [1,2,3] == False

isPermutationOf

isPermutationOf : List a -> List a -> Bool

True when the lists are permutations of each other.

Examples

isPermutationOf [1,2,3] [3,1,2] == True
isPermutationOf [1,2] [1,2,2] == False

notMember

notMember : a -> List a -> Bool

True when a value is not in the list.

Examples

notMember 9 [1,2,3] == True
notMember 2 [1,2,3] == False

find

find : (a -> Bool) -> List a -> Maybe a

First element that matches a predicate.

Examples

find (\n -> n > 2) [1,2,3,4] == Just 3
find (\n -> n > 9) [1,2] == Nothing

elemIndex

elemIndex : a -> List a -> Maybe Int

Index of the first matching value.

Examples

elemIndex 2 [1,2,3,2] == Just 1
elemIndex 9 [1,2,3] == Nothing

elemIndices

elemIndices : a -> List a -> List Int

All indices of a value.

Examples

elemIndices 2 [1,2,3,2] == [1,3]

findIndex

findIndex : (a -> Bool) -> List a -> Maybe Int

Index of the first matching predicate.

Examples

findIndex (\n -> n > 2) [1,2,3,4] == Just 2

findIndices

findIndices : (a -> Bool) -> List a -> List Int

All indices matching a predicate.

Examples

findIndices (\n -> n > 2) [1,2,3,4] == [2,3]

findMap

findMap : (a -> Maybe b) -> List a -> Maybe b

First successful Maybe from mapping.

Examples

findMap String.toInt ["a","12","b"] == Just 12
findMap String.toInt ["a","b"] == Nothing

count

count : (a -> Bool) -> List a -> Int

Count elements that match a predicate.

Examples

count (\n -> n > 2) [1,2,3,4] == 2

zip

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 c

Apply 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 d

Apply 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 e

Apply 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 c

Inner 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"})]