File tree Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -56,3 +56,19 @@ let isSome = function
5656let isNone = function
5757 | Some _ -> false
5858 | 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
3737val getWithDefault : 'a option -> 'a -> 'a
3838val isSome : 'a option -> bool
3939val 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) {
7070 }
7171}
7272
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+
73109exports . getExn = getExn ;
74110exports . foldU = foldU ;
75111exports . fold = fold ;
76112exports . mapU = mapU ;
77113exports . map = map ;
78114exports . flatMapU = flatMapU ;
79115exports . 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 ;
83123/* No side effect */
You can’t perform that action at this time.
0 commit comments