Skip to content

Commit

Permalink
exposing either functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
phixid committed Dec 20, 2017
1 parent 439fb9e commit 9f6a188
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
17 changes: 17 additions & 0 deletions dist/cjs/subterfuge.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,26 @@ const composeRight = (func1, func2) => (...args) => func1(func2(...args));
const pipeLeft = (...funcs) => funcs.reduce(composeLeft);
const pipeRight = (...funcs) => funcs.reduce(composeRight);

const Left = value => ({
map: func => Left(value),
fold: (errorhandler, successhandler) => errorhandler(value),
inspect: () => `Left(${value})`
});

const Right = value => ({
map: func => Right(func(value)),
fold: (errorhandler, successhandler) => successhandler(value),
inspect: () => `Right(${value})`
});

const Either = value => (value == null ? Left(value) : Right(value));

exports.Box = Box;
exports.LazyBox = LazyBox;
exports.composeLeft = composeLeft;
exports.composeRight = composeRight;
exports.pipeLeft = pipeLeft;
exports.pipeRight = pipeRight;
exports.Either = Either;
exports.Left = Left;
exports.Right = Right;
16 changes: 15 additions & 1 deletion dist/es/subterfuge.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,18 @@ const composeRight = (func1, func2) => (...args) => func1(func2(...args));
const pipeLeft = (...funcs) => funcs.reduce(composeLeft);
const pipeRight = (...funcs) => funcs.reduce(composeRight);

export { Box, LazyBox, composeLeft, composeRight, pipeLeft, pipeRight };
const Left = value => ({
map: func => Left(value),
fold: (errorhandler, successhandler) => errorhandler(value),
inspect: () => `Left(${value})`
});

const Right = value => ({
map: func => Right(func(value)),
fold: (errorhandler, successhandler) => successhandler(value),
inspect: () => `Right(${value})`
});

const Either = value => (value == null ? Left(value) : Right(value));

export { Box, LazyBox, composeLeft, composeRight, pipeLeft, pipeRight, Either, Left, Right };
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { Box } from './containers/box';
export { LazyBox } from './containers/lazybox';
export { composeLeft, composeRight } from './composition/compose';
export { pipeLeft, pipeRight } from './composition/pipe';
export { Either, Left, Right } from './containers/either';

0 comments on commit 9f6a188

Please sign in to comment.