-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfilterable.ts
More file actions
73 lines (71 loc) · 2.25 KB
/
Copy pathfilterable.ts
File metadata and controls
73 lines (71 loc) · 2.25 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Filterable is a structure that allows one to remove or refine a data
* structure.
*
* @module Filterable
* @since 2.0.0
*/
import type { $, Hold, Kind } from "./kind.ts";
import type { Either } from "./either.ts";
import type { Option } from "./option.ts";
import type { Pair } from "./pair.ts";
import type { Predicate } from "./predicate.ts";
import type { Refinement } from "./refinement.ts";
/**
* A Filterable structure allows one to filter over the values contained in the
* structure. This includes standard filter, filterMap, partition, and
* partitionMap.
*
* @example
* ```ts
* import type { Filterable } from "./filterable.ts";
* import * as A from "./array.ts";
* import { pipe } from "./fn.ts";
*
* // Example with Array filterable
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
* const evens = pipe(
* numbers,
* A.FilterableArray.filter(n => n % 2 === 0)
* );
* console.log(evens); // [2, 4, 6, 8, 10]
* ```
*
* @since 2.0.0
*/
export interface Filterable<U extends Kind> extends Hold<U> {
readonly filter: {
<A, I extends A>(
refinement: Refinement<A, I>,
): <B = never, C = never, D = unknown, E = unknown>(
ta: $<U, [A, B, C], [D], [E]>,
) => $<U, [I, B, C], [D], [E]>;
<A>(
predicate: Predicate<A>,
): <B = never, C = never, D = unknown, E = unknown>(
ta: $<U, [A, B, C], [D], [E]>,
) => $<U, [A, B, C], [D], [E]>;
};
readonly filterMap: <A, I>(
fai: (a: A) => Option<I>,
) => <B = never, C = never, D = unknown, E = unknown>(
ua: $<U, [A, B, C], [D], [E]>,
) => $<U, [I, B, C], [D], [E]>;
readonly partition: {
<A, I extends A>(
refinement: Refinement<A, I>,
): <B = never, C = never, D = unknown, E = unknown>(
ta: $<U, [A, B, C], [D], [E]>,
) => Pair<$<U, [I, B, C], [D], [E]>, $<U, [A, B, C], [D], [E]>>;
<A>(
predicate: Predicate<A>,
): <B = never, C = never, D = unknown, E = unknown>(
ta: $<U, [A, B, C], [D], [E]>,
) => Pair<$<U, [A, B, C], [D], [E]>, $<U, [A, B, C], [D], [E]>>;
};
readonly partitionMap: <A, I, J>(
fai: (a: A) => Either<J, I>,
) => <B = never, C = never, D = unknown, E = unknown>(
ua: $<U, [A, B, C], [D], [E]>,
) => Pair<$<U, [I, B, C], [D], [E]>, $<U, [J, B, C], [D], [E]>>;
}