File tree Expand file tree Collapse file tree 6 files changed +110
-0
lines changed
Expand file tree Collapse file tree 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
3434 belt_internalMapString\
3535 belt_MapString \
3636 belt_MapInt\
37+ belt_Option\
3738 belt_internalSet\
3839 belt_Set\
3940 belt_MutableSet\
Original file line number Diff line number Diff line change @@ -232,7 +232,11 @@ module HashSet = Belt_HashSet
232232*)
233233module HashMap = Belt_HashMap
234234
235+ (* * {!Belt.Option}
235236
237+ Utilities for option data type
238+ *)
236239
240+ module Option = Belt_Option
237241
238242
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;
2727
2828var HashMap = 0 ;
2929
30+ var Option = 0 ;
31+
3032exports . Id = Id ;
3133exports . $$Array = $$Array ;
3234exports . SortArray = SortArray ;
@@ -40,4 +42,5 @@ exports.MutableSet = MutableSet;
4042exports . MutableMap = MutableMap ;
4143exports . HashSet = HashSet ;
4244exports . HashMap = HashMap ;
45+ exports . Option = Option ;
4346/* 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