Iter

lib/Iter.gob

No module comment.

class Iterator c
fun iter : [Iterator c] fun(c) -> Cursor c
fun next : [Iterator c] fun(c, Cursor c) -> Option (Item c)
type Item c
type Cursor c
fun any : [Iterator c] fun(c, fun(Item c) -> Bool) -> Bool
fun all : [Iterator c] fun(c, fun(Item c) -> Bool) -> Bool
fun count : [Iterator c] fun(c, fun(Item c) -> Bool) -> Int

How many elements p holds for. It takes a predicate: how many elements there are is len, which a container answers without walking itself.

fun find : [Iterator c] fun(c, fun(Item c) -> Bool) -> Option (Item c)

The first element p holds for.

fun fold : [Iterator c] fun(c, b, fun(b, Item c) -> b) -> b

Returns the result of calling step on the accumulator and each element in turn, starting from initial. It takes its arguments in the order of Array.fold and Vec.fold, and works on anything iterable.

fun sum : [Iterator c, Add (Item c), Zero (Item c)] fun(c) -> Item c

Returns the elements added together from zero(), which is the result for no elements.

fun product : [Iterator c, Mul (Item c), One (Item c)] fun(c) -> Item c

Returns the elements multiplied together from one(), which is the result for no elements.

fun minimum : [Iterator c, Ord (Item c)] fun(c) -> Option (Item c)

Returns the least element, or None for no elements. Of several elements that are equal under <, it returns the first. A NaN is neither less than nor greater than anything, so a Float result depends on where a NaN sits: [nan, 1.0] gives NaN and [1.0, nan, 0.5] gives 0.5.

fun maximum : [Iterator c, Ord (Item c)] fun(c) -> Option (Item c)

Returns the greatest element, or None for no elements. Of several elements that are equal under <, it returns the first. A NaN is neither less than nor greater than anything, so a Float result depends on where a NaN sits.

fun minBy : [Iterator c, Ord k] fun(c, fun(Item c) -> k) -> Option (Item c)

Returns the element whose key is least, or None for no elements. It calls key once per element, and the first element wins a tie.

fun maxBy : [Iterator c, Ord k] fun(c, fun(Item c) -> k) -> Option (Item c)

Returns the element whose key is greatest, or None for no elements. It calls key once per element, and the first element wins a tie.

fun collect : [Iterator c] fun(c) -> Array (Item c)

Returns the elements of xs in order, as a fresh array.

type Enumerate c
fun enumerate : [Iterator c] fun(c) -> Enumerate c

Returns xs with each element paired with its position, counting from 0.

type Zip a b
fun zip : [Iterator a, Iterator b] fun(a, b) -> Zip a b

Returns the pairs of elements of xs and ys at the same position. Stops at the shorter input; each pull takes one from xs first, so an element of xs with no partner is consumed and dropped.

type Mapped c a b
fun map : [Iterator c, Item c ~ a] fun(c, fun(a) -> b) -> Mapped c a b

Returns f of each element of xs, computed as each is pulled. Array.map is the eager form, which builds an array.

type Filtered c a
fun filter : [Iterator c, Item c ~ a] fun(c, fun(a) -> Bool) -> Filtered c a

Returns the elements of xs that keep holds for. Array.filter is the eager form, which builds an array.

type TakeWhile c a
fun takeWhile : [Iterator c, Item c ~ a] fun(c, fun(a) -> Bool) -> TakeWhile c a

Returns the elements of xs up to the first one keep does not hold for. That first one is consumed and dropped.

type DropWhile c a
fun dropWhile : [Iterator c, Item c ~ a] fun(c, fun(a) -> Bool) -> DropWhile c a

Returns the elements of xs from the first one skip does not hold for.

type Take c
fun take : [Iterator c] fun(c, Int) -> Iter.Take c

Returns the first n elements of xs, or all of them if there are fewer. Pulls at most n from xs, and none when n is 0. Panics if n is negative.

type Drop c
fun drop : [Iterator c] fun(c, Int) -> Drop c

Returns the elements of xs after the first n. Panics if n is negative.

type Pairwise c
fun pairwise : [Iterator c] fun(c) -> Pairwise c

Returns each element of xs paired with the one after it: (x0, x1), (x1, x2), and so on. Empty if xs has fewer than two elements.

type Windowed c
fun windowed : [Iterator c] fun(c, Int) -> Windowed c

Returns every run of n consecutive elements of xs, each as a fresh array: [x0, x1, x2], [x1, x2, x3], and so on. Empty if xs has fewer than n. Allocates one array of n per window. Panics if n is less than 1.

type Chunked c
fun chunked : [Iterator c] fun(c, Int) -> Chunked c

Returns the elements of xs in consecutive groups of n, each as a fresh array; the last group is shorter if the elements run out. Allocates one array per group, and one buffer per walk that grows to the largest group. Panics if n is less than 1.

type CountFrom
fun countFrom : fun(Int) -> CountFrom

Returns n, n + 1, n + 2, and so on without end. A loop over it ends only by break or return, or by an adapter such as takeWhile.

type Cycle c
fun cycle : [Iterator c] fun(c) -> Cycle c

Returns the elements of xs over and over without end, starting xs again each time it runs out. Empty if xs is empty.

type Chain a b
fun chain : [Iterator a, Iterator b, Item b ~ Item a] fun(a, b) -> Chain a b

Returns the elements of xs and then those of ys.

type Combinations a
fun combinations : fun(Array a, Int) -> Combinations a

Returns every choice of k elements of xs, in the order they appear in xs, without repetition: for [1, 2, 3] and 2, [1, 2], [1, 3], [2, 3]. One empty choice if k is 0, none if k exceeds len(xs). Allocates one array of k per choice. Panics if k is negative.

type Permutations a
fun permutations : fun(Array a, Int) -> Permutations a

Returns every ordering of k distinct elements of xs (distinct by position): for [1, 2, 3] and 2, [1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]. One empty ordering if k is 0, none if k exceeds len(xs). Allocates one array of k per ordering. Panics if k is negative.

type Cartesian a b
fun cartesian : [Iterator a, Iterator b] fun(a, b) -> Cartesian a b

Returns every pair of an element of xs and an element of ys, xs varying slowest: for [1, 2] and ["a", "b"], (1, "a"), (1, "b"), (2, "a"), (2, "b"). Iterates ys again from the start for each element of xs. Empty if ys is, even when xs is endless.

type CartesianPower a
fun cartesianPower : fun(Array a, Int) -> CartesianPower a

Returns every array of n elements drawn from xs, repeats allowed, the last position varying fastest. For [0, 1] and 2, [0, 0], [0, 1], [1, 0], [1, 1]. One empty array if n is 0. Allocates one array of n per element. Panics if n is negative.

instance Iterator (Enumerate c) : Iterator c
instance Iterator (Zip a b) : Iterator a, Iterator b
instance Iterator (Mapped c a b) : Iterator c, Item c ~ a
instance Iterator (Filtered c a) : Iterator c, Item c ~ a
instance Iterator (TakeWhile c a) : Iterator c, Item c ~ a
instance Iterator (DropWhile c a) : Iterator c, Item c ~ a
instance Iterator (Iter.Take c) : Iterator c
instance Iterator (Drop c) : Iterator c
instance Iterator (Pairwise c) : Iterator c
instance Iterator (Windowed c) : Iterator c
instance Iterator (Chunked c) : Iterator c
instance Iterator CountFrom
instance Iterator (Cycle c) : Iterator c
instance Iterator (Chain a b) : Iterator a, Iterator b, Item b ~ Item a
instance Iterator (Combinations a)
instance Iterator (Permutations a)
instance Iterator (Cartesian a b) : Iterator a, Iterator b
instance Iterator (CartesianPower a)