File tree 6 files changed +110
-0
lines changed
6 files changed +110
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
34
34
belt_internalMapString\
35
35
belt_MapString \
36
36
belt_MapInt\
37
+ belt_Option\
37
38
belt_internalSet\
38
39
belt_Set\
39
40
belt_MutableSet\
Original file line number Diff line number Diff line change @@ -232,7 +232,11 @@ module HashSet = Belt_HashSet
232
232
*)
233
233
module HashMap = Belt_HashMap
234
234
235
+ (* * {!Belt.Option}
235
236
237
+ Utilities for option data type
238
+ *)
236
239
240
+ module Option = Belt_Option
237
241
238
242
Original file line number Diff line number Diff line change
1
+ let getExn = function
2
+ | Some x -> x
3
+ | None -> assert false
4
+
5
+ let fold opt default f = match opt with
6
+ | Some x -> f x
7
+ | None -> default
8
+
9
+ let map opt f = match opt with
10
+ | Some x -> Some (f x)
11
+ | None -> None
12
+
13
+ let flatMap opt f = match opt with
14
+ | Some x -> f x
15
+ | None -> None
16
+
17
+ let getOrElse opt default = match opt with
18
+ | Some x -> x
19
+ | None -> default
20
+
21
+ let exists = function
22
+ | Some _ -> true
23
+ | None -> false
24
+
25
+ let empty = function
26
+ | Some _ -> false
27
+ | None -> true
Original file line number Diff line number Diff line change
1
+ val getExn : 'a option -> 'a
2
+ val fold : 'a option -> 'b -> ('a -> 'b ) -> 'b
3
+ val map : 'a option -> ('a -> 'b ) -> 'b option
4
+ val flatMap : 'a option -> ('a -> 'b option ) -> 'b option
5
+ val getOrElse : 'a option -> 'a -> 'a
6
+ val exists : 'a option -> bool
7
+ val empty : 'a option -> bool
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ var HashSet = 0;
27
27
28
28
var HashMap = 0 ;
29
29
30
+ var Option = 0 ;
31
+
30
32
exports . Id = Id ;
31
33
exports . $$Array = $$Array ;
32
34
exports . SortArray = SortArray ;
@@ -40,4 +42,5 @@ exports.MutableSet = MutableSet;
40
42
exports . MutableMap = MutableMap ;
41
43
exports . HashSet = HashSet ;
42
44
exports . HashMap = HashMap ;
45
+ exports . Option = Option ;
43
46
/* No side effect */
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var Curry = require ( "./curry.js" ) ;
4
+
5
+ function getExn ( param ) {
6
+ if ( param ) {
7
+ return param [ 0 ] ;
8
+ } else {
9
+ return /* assert false */ 0 ;
10
+ }
11
+ }
12
+
13
+ function fold ( opt , $$default , f ) {
14
+ if ( opt ) {
15
+ return Curry . _1 ( f , opt [ 0 ] ) ;
16
+ } else {
17
+ return $$default ;
18
+ }
19
+ }
20
+
21
+ function map ( opt , f ) {
22
+ if ( opt ) {
23
+ return /* Some */ [ Curry . _1 ( f , opt [ 0 ] ) ] ;
24
+ } else {
25
+ return /* None */ 0 ;
26
+ }
27
+ }
28
+
29
+ function flatMap ( opt , f ) {
30
+ if ( opt ) {
31
+ return Curry . _1 ( f , opt [ 0 ] ) ;
32
+ } else {
33
+ return /* None */ 0 ;
34
+ }
35
+ }
36
+
37
+ function getOrElse ( opt , $$default ) {
38
+ if ( opt ) {
39
+ return opt [ 0 ] ;
40
+ } else {
41
+ return $$default ;
42
+ }
43
+ }
44
+
45
+ function exists ( param ) {
46
+ if ( param ) {
47
+ return /* true */ 1 ;
48
+ } else {
49
+ return /* false */ 0 ;
50
+ }
51
+ }
52
+
53
+ function empty ( param ) {
54
+ if ( param ) {
55
+ return /* false */ 0 ;
56
+ } else {
57
+ return /* true */ 1 ;
58
+ }
59
+ }
60
+
61
+ exports . getExn = getExn ;
62
+ exports . fold = fold ;
63
+ exports . map = map ;
64
+ exports . flatMap = flatMap ;
65
+ exports . getOrElse = getOrElse ;
66
+ exports . exists = exists ;
67
+ exports . empty = empty ;
68
+ /* No side effect */
You can’t perform that action at this time.
0 commit comments