-
Notifications
You must be signed in to change notification settings - Fork 6
/
traversable.ts
31 lines (29 loc) · 1.01 KB
/
traversable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Traversable is a structure that encapsulates the idea of iterating through
* data and collecting it into another structure. This can be as simple as
* turning an Array<Option<number>> into Option<Array<number>> or as complicated
* as creating all combinations of numbers in three Array<numbers>.
*
* @module Traversable
* @since 2.0.0
*/
import type { $, Hold, Kind } from "./kind.ts";
import type { Applicable } from "./applicable.ts";
import type { Mappable } from "./mappable.ts";
import type { Foldable } from "./foldable.ts";
/**
* A Traversable structure extends Mappable and Foldable. It contains the
* methods map, fold, and traverse.
*
* @since 2.0.0
*/
export interface Traversable<U extends Kind>
extends Mappable<U>, Foldable<U>, Hold<U> {
readonly traverse: <VRI extends Kind>(
A: Applicable<VRI>,
) => <A, I, J, K, L, M>(
faui: (a: A) => $<VRI, [I, J, K], [L], [M]>,
) => <B, C, D, E>(
ta: $<U, [A, B, C], [D], [E]>,
) => $<VRI, [$<U, [I, B, C], [D], [E]>, J, K], [L], [M]>;
}