Skip to content

Commit

Permalink
Merge 6ed6ca2 into 38b7386
Browse files Browse the repository at this point in the history
  • Loading branch information
arnarthor committed Mar 14, 2018
2 parents 38b7386 + 6ed6ca2 commit d8d0a0e
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions jscomp/others/Makefile
Expand Up @@ -34,6 +34,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
belt_internalMapString\
belt_MapString \
belt_MapInt\
belt_Option\
belt_internalSet\
belt_Set\
belt_MutableSet\
Expand Down
4 changes: 4 additions & 0 deletions jscomp/others/belt.ml
Expand Up @@ -232,7 +232,11 @@ module HashSet = Belt_HashSet
*)
module HashMap = Belt_HashMap

(** {!Belt.Option}
Utilities for option data type
*)

module Option = Belt_Option


27 changes: 27 additions & 0 deletions jscomp/others/belt_Option.ml
@@ -0,0 +1,27 @@
let getExn = function
| Some x -> x
| None -> assert false

let fold opt default f = match opt with
| Some x -> f x
| None -> default

let map opt f = match opt with
| Some x -> Some (f x)
| None -> None

let flatMap opt f = match opt with
| Some x -> f x
| None -> None

let getOrElse opt default = match opt with
| Some x -> x
| None -> default

let exists = function
| Some _ -> true
| None -> false

let empty = function
| Some _ -> false
| None -> true
7 changes: 7 additions & 0 deletions jscomp/others/belt_Option.mli
@@ -0,0 +1,7 @@
val getExn : 'a option -> 'a
val fold : 'a option -> 'b -> ('a -> 'b) -> 'b
val map : 'a option -> ('a -> 'b) -> 'b option
val flatMap : 'a option -> ('a -> 'b option) -> 'b option
val getOrElse : 'a option -> 'a -> 'a
val exists : 'a option -> bool
val empty : 'a option -> bool
3 changes: 3 additions & 0 deletions lib/js/belt.js
Expand Up @@ -27,6 +27,8 @@ var HashSet = 0;

var HashMap = 0;

var Option = 0;

exports.Id = Id;
exports.$$Array = $$Array;
exports.SortArray = SortArray;
Expand All @@ -40,4 +42,5 @@ exports.MutableSet = MutableSet;
exports.MutableMap = MutableMap;
exports.HashSet = HashSet;
exports.HashMap = HashMap;
exports.Option = Option;
/* No side effect */
68 changes: 68 additions & 0 deletions lib/js/belt_Option.js
@@ -0,0 +1,68 @@
'use strict';

var Curry = require("./curry.js");

function getExn(param) {
if (param) {
return param[0];
} else {
return /* assert false */0;
}
}

function fold(opt, $$default, f) {
if (opt) {
return Curry._1(f, opt[0]);
} else {
return $$default;
}
}

function map(opt, f) {
if (opt) {
return /* Some */[Curry._1(f, opt[0])];
} else {
return /* None */0;
}
}

function flatMap(opt, f) {
if (opt) {
return Curry._1(f, opt[0]);
} else {
return /* None */0;
}
}

function getOrElse(opt, $$default) {
if (opt) {
return opt[0];
} else {
return $$default;
}
}

function exists(param) {
if (param) {
return /* true */1;
} else {
return /* false */0;
}
}

function empty(param) {
if (param) {
return /* false */0;
} else {
return /* true */1;
}
}

exports.getExn = getExn;
exports.fold = fold;
exports.map = map;
exports.flatMap = flatMap;
exports.getOrElse = getOrElse;
exports.exists = exists;
exports.empty = empty;
/* No side effect */

0 comments on commit d8d0a0e

Please sign in to comment.