UNPKG

1.42 kBTypeScriptView Raw
1/**
2 * Lisp-like sequence abstraction for arbitrary types using `first` &
3 * `next` operations only.
4 *
5 * @remarks
6 * Unlike ES6 iterators this approach does not conflate both operations
7 * and `first()` can be called any number of times to obtain the current
8 * value (if any) from the sequence.
9 */
10export interface ISeq<T> {
11 /**
12 * Returns the sequence's first value or `undefined` if there're no
13 * further values.
14 *
15 * @remarks
16 * If the sequence is guaranteed to not include `undefined` values,
17 * a simple check for `seq.first() === undefined` is sufficient to
18 * determine the end. If the sequence DOES contain `undefined`
19 * values, the check should use `seq.next()`.
20 */
21 first(): T | undefined;
22 /**
23 * Returns a new sequence of the remaining elements or `undefined`
24 * if there're no further values.
25 *
26 * @remarks
27 * In general, implementations of this interface MUST always return
28 * a new sequence instance and not mutate some internal cursor. I.e.
29 * `seq.next() !== seq`
30 */
31 next(): ISeq<T> | undefined;
32}
33/**
34 * Interface for data types providing an {@link ISeq} abstraction.
35 */
36export interface ISeqable<T> {
37 /**
38 * Returns an {@link ISeq} of the type's data or `undefined` if
39 * there're no values available. See {@link ISeq.next}
40 */
41 seq(): ISeq<T> | undefined;
42}
43//# sourceMappingURL=seq.d.ts.map
\No newline at end of file