Skip to content

Commit 061a9c6

Browse files
committed
feat(nullable): add map
1 parent 60dda55 commit 061a9c6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Core__Nullable.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3+
import * as Curry from "rescript/lib/es6/curry.js";
34
import * as Caml_option from "rescript/lib/es6/caml_option.js";
45

56
function fromOption(option) {
@@ -28,9 +29,17 @@ function getExn(value) {
2829
};
2930
}
3031

32+
function map(value, f) {
33+
if (!(value == null)) {
34+
return Caml_option.some(Curry._1(f, value));
35+
}
36+
37+
}
38+
3139
export {
3240
fromOption ,
3341
getWithDefault ,
3442
getExn ,
43+
map ,
3544
}
3645
/* No side effect */

src/Core__Nullable.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ let getExn: t<'a> => 'a = value =>
2727
}
2828

2929
external getUnsafe: t<'a> => 'a = "%identity"
30+
31+
let map = (value, f) =>
32+
switch value->toOption {
33+
| Some(x) => Some(f(x))
34+
| None => None
35+
}

0 commit comments

Comments
 (0)