UNPKG

1.88 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6
7var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
8
9function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
10
11function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
12
13var _lodashCurry = require('lodash.curry');
14
15var _lodashCurry2 = _interopRequireDefault(_lodashCurry);
16
17var _fp = require('../fp');
18
19var Either = (function () {
20 function Either(left, right) {
21 _classCallCheck(this, Either);
22
23 this.left = left;
24 this.right = right;
25 }
26
27 _createClass(Either, [{
28 key: 'map',
29 value: function map(f) {
30 if ((0, _fp.falcy)(this.right)) {
31 return new Either(f(this.left), this.right);
32 }
33 return new Either(this.left, f(this.right));
34 }
35 }, {
36 key: 'extract',
37 value: function extract() {
38 return (0, _fp.falcy)(this.right) ? this.left : this.right;
39 }
40 }, {
41 key: 'chain',
42 value: function chain(f) {
43 return f((0, _fp.falcy)(this.right) ? this.left : this.right);
44 }
45 }]);
46
47 return Either;
48})();
49
50Either.of = (0, _lodashCurry2['default'])(function (left, right) {
51 return new Either(left, right);
52});
53
54exports['default'] = Either;
55module.exports = exports['default'];
\No newline at end of file