|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Block = require("./block.js"); |
| 4 | +var Curry = require("./curry.js"); |
| 5 | + |
| 6 | +function getExn(param) { |
| 7 | + if (param.tag) { |
| 8 | + throw new Error("getExn"); |
| 9 | + } else { |
| 10 | + return param[0]; |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +function mapWithDefaultU(opt, $$default, f) { |
| 15 | + if (opt.tag) { |
| 16 | + return $$default; |
| 17 | + } else { |
| 18 | + return f(opt[0]); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +function mapWithDefault(opt, $$default, f) { |
| 23 | + return mapWithDefaultU(opt, $$default, Curry.__1(f)); |
| 24 | +} |
| 25 | + |
| 26 | +function mapU(opt, f) { |
| 27 | + if (opt.tag) { |
| 28 | + return /* Error */Block.__(1, [opt[0]]); |
| 29 | + } else { |
| 30 | + return /* Ok */Block.__(0, [f(opt[0])]); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +function map(opt, f) { |
| 35 | + return mapU(opt, Curry.__1(f)); |
| 36 | +} |
| 37 | + |
| 38 | +function flatMapU(opt, f) { |
| 39 | + if (opt.tag) { |
| 40 | + return /* Error */Block.__(1, [opt[0]]); |
| 41 | + } else { |
| 42 | + return f(opt[0]); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function flatMap(opt, f) { |
| 47 | + return flatMapU(opt, Curry.__1(f)); |
| 48 | +} |
| 49 | + |
| 50 | +function getWithDefault(opt, $$default) { |
| 51 | + if (opt.tag) { |
| 52 | + return $$default; |
| 53 | + } else { |
| 54 | + return opt[0]; |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +function isOk(param) { |
| 59 | + if (param.tag) { |
| 60 | + return /* false */0; |
| 61 | + } else { |
| 62 | + return /* true */1; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +function isError(param) { |
| 67 | + if (param.tag) { |
| 68 | + return /* true */1; |
| 69 | + } else { |
| 70 | + return /* false */0; |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +function eqU(a, b, f) { |
| 75 | + if (a.tag) { |
| 76 | + if (b.tag) { |
| 77 | + return /* true */1; |
| 78 | + } else { |
| 79 | + return /* false */0; |
| 80 | + } |
| 81 | + } else if (b.tag) { |
| 82 | + return /* false */0; |
| 83 | + } else { |
| 84 | + return f(a[0], b[0]); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +function eq(a, b, f) { |
| 89 | + return eqU(a, b, Curry.__2(f)); |
| 90 | +} |
| 91 | + |
| 92 | +function cmpU(a, b, f) { |
| 93 | + if (a.tag) { |
| 94 | + if (b.tag) { |
| 95 | + return 0; |
| 96 | + } else { |
| 97 | + return -1; |
| 98 | + } |
| 99 | + } else if (b.tag) { |
| 100 | + return 1; |
| 101 | + } else { |
| 102 | + return f(a[0], b[0]); |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +function cmp(a, b, f) { |
| 107 | + return cmpU(a, b, Curry.__2(f)); |
| 108 | +} |
| 109 | + |
| 110 | +exports.getExn = getExn; |
| 111 | +exports.mapWithDefaultU = mapWithDefaultU; |
| 112 | +exports.mapWithDefault = mapWithDefault; |
| 113 | +exports.mapU = mapU; |
| 114 | +exports.map = map; |
| 115 | +exports.flatMapU = flatMapU; |
| 116 | +exports.flatMap = flatMap; |
| 117 | +exports.getWithDefault = getWithDefault; |
| 118 | +exports.isOk = isOk; |
| 119 | +exports.isError = isError; |
| 120 | +exports.eqU = eqU; |
| 121 | +exports.eq = eq; |
| 122 | +exports.cmpU = cmpU; |
| 123 | +exports.cmp = cmp; |
| 124 | +/* No side effect */ |
0 commit comments