Document List.map2 and List.map3

This commit is contained in:
Richard Feldman 2021-10-04 08:39:09 -04:00
parent e6ec1ded22
commit cfe7d5afbb

View file

@ -6,7 +6,6 @@ interface List
get, get,
set, set,
append, append,
map,
len, len,
walkBackwards, walkBackwards,
concat, concat,
@ -23,9 +22,12 @@ interface List
last, last,
keepOks, keepOks,
keepErrs, keepErrs,
mapWithIndex, map,
map2, map2,
map3, map3,
mapWithIndex,
mapOrDrop,
mapJoin,
product, product,
walkUntil, walkUntil,
range, range,
@ -250,6 +252,21 @@ sortDesc : List elem, (elem -> Num *) -> List elem
## See for example `Set.map`, `Dict.map`, and [Result.map]. ## See for example `Set.map`, `Dict.map`, and [Result.map].
map : List before, (before -> after) -> List after map : List before, (before -> after) -> List after
## Run a transformation function on the first element of each list,
## and use that as the first element in the returned list.
## Repeat until a list runs out of elements.
##
## Some languages have a function named `zip`, which does something similar to
## calling [List.map2] passing two lists and `Pair`:
##
## >>> zipped = List.map2 [ "a", "b", "c" ] [ 1, 2, 3 ] Pair
map2 : List a, List b, (a, b -> c) -> List c
## Run a transformation function on the first element of each list,
## and use that as the first element in the returned list.
## Repeat until a list runs out of elements.
map3 : List a, List b, List c, (a, b, c -> d) -> List d
## This works like [List.map], except it also passes the index ## This works like [List.map], except it also passes the index
## of the element to the conversion function. ## of the element to the conversion function.
mapWithIndex : List before, (before, Nat -> after) -> List after mapWithIndex : List before, (before, Nat -> after) -> List after
@ -349,28 +366,6 @@ join : List (List elem) -> List elem
## so we're sticking with `Result` for now. ## so we're sticking with `Result` for now.
oks : List (Result elem *) -> List elem oks : List (Result elem *) -> List elem
## Iterates over the shortest of the given lists and returns a list of `Pair`
## tags, each wrapping one of the elements in that list, along with the elements
## in the same index in # the other lists.
##
## >>> List.zip [ "a1", "b1" "c1" ] [ "a2", "b2" ] [ "a3", "b3", "c3" ]
##
## Accepts up to 8 lists.
##
## > For a generalized version that returns whatever you like, instead of a `Pair`,
## > see `zipMap`.
zip : List a, List b -> List [ Pair a b ]*
## Like `zip` but you can specify what to do with each element.
##
## More specifically, [repeat what zip's docs say here]
##
## >>> List.zipMap [ 1, 2, 3 ] [ 0, 5, 4 ] [ 2, 1 ] \num1 num2 num3 -> num1 + num2 - num3
##
## Accepts up to 8 lists.
zipMap : List a, List b, (a, b -> c) -> List c
## Filter ## Filter
## Run the given function on each element of a list, and return all the ## Run the given function on each element of a list, and return all the