File tree 3 files changed +63
-3
lines changed
3 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -56,3 +56,19 @@ let isSome = function
56
56
let isNone = function
57
57
| Some _ -> false
58
58
| None -> true
59
+
60
+ let eqU a b f = match (a, b) with
61
+ | (Some a , Some b ) -> f a b [@ bs]
62
+ | (None , Some _)
63
+ | (Some _ , None) -> false
64
+ | (None, None) -> true
65
+
66
+ let eq a b f = eqU a b (fun[@ bs] x y -> f x y)
67
+
68
+ let cmpU a b f = match (a, b) with
69
+ | (Some a , Some b ) -> f a b [@ bs]
70
+ | (None, Some _ ) -> - 1
71
+ | (Some _ , None) -> 1
72
+ | (None, None) -> 0
73
+
74
+ let cmp a b f = cmpU a b (fun[@ bs] x y -> f x y)
Original file line number Diff line number Diff line change @@ -37,3 +37,7 @@ val flatMap : 'a option -> ('a -> 'b option) -> 'b option
37
37
val getWithDefault : 'a option -> 'a -> 'a
38
38
val isSome : 'a option -> bool
39
39
val isNone : 'a option -> bool
40
+ val eqU : 'a option -> 'b option -> ('a -> 'b -> bool [@ bs]) -> bool
41
+ val eq : 'a option -> 'b option -> ('a -> 'b -> bool ) -> bool
42
+ val cmpU : 'a option -> 'b option -> ('a -> 'b -> int [@ bs]) -> int
43
+ val cmp : 'a option -> 'b option -> ('a -> 'b -> int ) -> int
Original file line number Diff line number Diff line change @@ -70,14 +70,54 @@ function isNone(param) {
70
70
}
71
71
}
72
72
73
+ function eqU ( a , b , f ) {
74
+ if ( a ) {
75
+ if ( b ) {
76
+ return f ( a [ 0 ] , b [ 0 ] ) ;
77
+ } else {
78
+ return /* false */ 0 ;
79
+ }
80
+ } else if ( b ) {
81
+ return /* false */ 0 ;
82
+ } else {
83
+ return /* true */ 1 ;
84
+ }
85
+ }
86
+
87
+ function eq ( a , b , f ) {
88
+ return eqU ( a , b , Curry . __2 ( f ) ) ;
89
+ }
90
+
91
+ function cmpU ( a , b , f ) {
92
+ if ( a ) {
93
+ if ( b ) {
94
+ return f ( a [ 0 ] , b [ 0 ] ) ;
95
+ } else {
96
+ return 1 ;
97
+ }
98
+ } else if ( b ) {
99
+ return - 1 ;
100
+ } else {
101
+ return 0 ;
102
+ }
103
+ }
104
+
105
+ function cmp ( a , b , f ) {
106
+ return cmpU ( a , b , Curry . __2 ( f ) ) ;
107
+ }
108
+
73
109
exports . getExn = getExn ;
74
110
exports . foldU = foldU ;
75
111
exports . fold = fold ;
76
112
exports . mapU = mapU ;
77
113
exports . map = map ;
78
114
exports . flatMapU = flatMapU ;
79
115
exports . flatMap = flatMap ;
80
- exports . getOrElse = getOrElse ;
81
- exports . has = has ;
82
- exports . isEmpty = isEmpty ;
116
+ exports . getWithDefault = getWithDefault ;
117
+ exports . isSome = isSome ;
118
+ exports . isNone = isNone ;
119
+ exports . eqU = eqU ;
120
+ exports . eq = eq ;
121
+ exports . cmpU = cmpU ;
122
+ exports . cmp = cmp ;
83
123
/* No side effect */
You can’t perform that action at this time.
0 commit comments