-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathRelude_Extensions_Functor.re
More file actions
73 lines (62 loc) · 2.1 KB
/
Copy pathRelude_Extensions_Functor.re
File metadata and controls
73 lines (62 loc) · 2.1 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
/**
Extensions for any FUNCTOR
*/
module FunctorExtensions = (F: Bastet.Interface.FUNCTOR) => {
module BsFunctorExtensions = Bastet.Functions.Functor(F);
/**
Flipped version of the map function which has the functor on the left, and the
function on the right.
*/
let flipMap: 'a 'b. (F.t('a), 'a => 'b) => F.t('b) =
(fa, f) => F.map(f, fa);
/**
Clears the value(s) of a functor by mapping a function that produces unit for
each value in the functor.
*/
let void: 'a. F.t('a) => F.t(unit) = BsFunctorExtensions.void;
/**
Replaces the value(s) of the functor on the right with the value on the left.
*/
let voidRight: 'a 'b. ('a, F.t('b)) => F.t('a) = BsFunctorExtensions.void_right;
/**
Replaces the value(s) of the functor on the left with the value on the right.
*/
let voidLeft: 'a 'b. (F.t('a), 'b) => F.t('b) = BsFunctorExtensions.void_left;
/**
Applies an argument of type ['a] to a functor of ['a => 'b] functions, to
produce a functor of ['b]
*/
let flap: 'a 'b. (F.t('a => 'b), 'a) => F.t('b) = BsFunctorExtensions.flap;
};
/**
Infix operator extensions for any FUNCTOR
*/
module FunctorInfix = (F: Bastet.Interface.FUNCTOR) => {
module FunctorExtensions = FunctorExtensions(F);
/**
Operator version of the [map] function, which has the function on the left,
and functor on the right.
*/
let (<$>) = F.map;
/**
Operator version of the [flipMap] function, which has the functor on the left,
and function on the right.
*/
let (<$$>) = FunctorExtensions.flipMap;
/**
Operator version of voidRight, which replaces the values of the functor on the
right with the value on the left.
*/
let (<$) = FunctorExtensions.voidRight;
/**
Operator version of voidLeft, which replaces the values of the functor on the
left with the value on the right.
*/
let ($>) = FunctorExtensions.voidLeft;
/**
Operator version of flap, which takes a functor of functions [F.t('a => 'b)]
on the left, and an ['a] on the right, and applies the value ['a] to each
function, producing a functor of ['b] ([F.t('b)]).
*/
let (<@>) = FunctorExtensions.flap;
};