Skip to content

Commit 0996e25

Browse files
committed
feat(nullable): add flatMap
1 parent 9f14f38 commit 0996e25

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Core__Nullable.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ function mapWithDefault(value, $$default, f) {
4444
}
4545
}
4646

47+
function flatMap(value, f) {
48+
if (!(value == null)) {
49+
return Curry._1(f, value);
50+
}
51+
52+
}
53+
4754
export {
4855
fromOption ,
4956
getWithDefault ,
5057
getExn ,
5158
map ,
5259
mapWithDefault ,
60+
flatMap ,
5361
}
5462
/* No side effect */

src/Core__Nullable.res

+6
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ let mapWithDefault = (value, default, f) =>
3939
| Some(x) => f(x)
4040
| None => default
4141
}
42+
43+
let flatMap = (value, f) =>
44+
switch value->toOption {
45+
| Some(x) => f(x)
46+
| None => undefined
47+
}

0 commit comments

Comments
 (0)