1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _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 |
|
9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
10 |
|
11 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
12 |
|
13 | var _lodashCurry = require('lodash.curry');
|
14 |
|
15 | var _lodashCurry2 = _interopRequireDefault(_lodashCurry);
|
16 |
|
17 | var _fp = require('../fp');
|
18 |
|
19 | var 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 |
|
50 | Either.of = (0, _lodashCurry2['default'])(function (left, right) {
|
51 | return new Either(left, right);
|
52 | });
|
53 |
|
54 | exports['default'] = Either;
|
55 | module.exports = exports['default']; |
\ | No newline at end of file |