Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |