mezzanine
Version:
Fantasy land union types with pattern matching
59 lines (52 loc) • 1.61 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.fantasyStatic = exports.fantasyMethods = undefined;
var _ramda = require('ramda');
var _list = require('../utils/list');
require('./type-container');
var fantasyMethods = exports.fantasyMethods = {
equals: (ctx, Record) => val => {
if (!Record.is(val)) return false;
var asTyped = Record.of(val);
var json = ctx.toJSON();
return (0, _ramda.equals)(json, asTyped.toJSON());
},
concat: (ctx, Record) => val => {
var struct = Record.
of(val).
toJSON();
return Record((0, _ramda.merge)(ctx.toJSON(), struct));
},
extract: ctx => function extract() {return ctx.toJSON();},
ap: ctx =>
function ap(m) {return m.chain(f => ctx.map(f));},
extend: (ctx, Record) =>
function extend(fn) {return Record(fn(ctx));},
chain: ctx =>
fn =>
fn(ctx.toJSON()),
map: (ctx, Record) =>
fn =>
Record(fn(ctx)) };
var fantasyStatic = exports.fantasyStatic = {
of: Record => val =>
typeof val === 'object' &&
val != null &&
Record.ಠ_ಠ === val.ಠ_ಠ ?
val :
Record(val),
equals: () => (a, b) => a.equals(b),
contramap: Record => fn => {
//$FlowIssue
var newStack = (0, _list.append)(fn, Record.stack);
//$FlowIssue
var NewRecord = Record.stackUpdate(newStack);
return NewRecord;
},
map: Record => fn => {
//$FlowIssue
var newStack = (0, _list.cons)(fn, Record.stack);
//$FlowIssue
var NewRecord = Record.stackUpdate(newStack);
return NewRecord;
} };exports.default =
fantasyMethods;
//# sourceMappingURL=fantasy-land.js.map