unfold
Summary
Produces a list of values from x.
Tip
This function is curried.
Description
First the predicate pred is applied to x.
If logical true the result of applying map to x is added to the list.
Then the predicate is applied to the next value of x which is
obtained by applying next to x and the process repeats until
the predicate returns logical false.
Examples
List of ten consecutive days starting from Wednesday.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
-
Continues unfolding whilst the current value of
xsatisfies the predicate. -
Transforms
x. The result is accumulated into the list. -
Returns the next value for
x. -
Starting value for
x.
Parameters
| Name | Type | Description |
|---|---|---|
| pred | function |
unfold continues whilst the predicate applied to x returns true. |
| map | function |
unfold applies map to x and adds the result to the list. |
| next | function |
unfold determines the next value of x by applying next to it. |
| x | * |
Return
Array.<*>