Comparing version 3.0.4 to 3.1.0
const FL = require('fantasy-land'); | ||
const Task = require('./task'); | ||
const Maybe = require('./maybe'); | ||
const Result = require('./result'); | ||
const Validation = require('./validation'); | ||
const { union } = require('./adt'); | ||
@@ -61,2 +66,30 @@ const { always, curry, compose } = require('./_tools'); | ||
// toMaybe :: Either a b -> Maybe b | ||
Either.toMaybe = either => | ||
either.cata({ | ||
Left: always(Maybe.Nothing), | ||
Right: Maybe.Just, | ||
}); | ||
// toResult :: Either a b -> Result a b | ||
Either.toResult = either => | ||
either.cata({ | ||
Left: Result.Err, | ||
Right: Result.Ok, | ||
}); | ||
// toValidation :: Either a b -> Validation a b | ||
Either.toValidation = either => | ||
either.cata({ | ||
Left: Validation.Failure.of, | ||
Right: Validation.Success.of, | ||
}); | ||
// toTask :: Either a b -> Task a b | ||
Either.toTask = either => | ||
either.cata({ | ||
Left: Task.reject, | ||
Right: Task.of, | ||
}); | ||
Either.try = callback => (...args) => { | ||
@@ -124,3 +157,22 @@ try { | ||
// toMaybe :: Either a b ~> Maybe b | ||
Either.prototype.toMaybe = function toMaybe() { | ||
return Either.toMaybe(this); | ||
}; | ||
// toResult :: Either a b ~> Result a b | ||
Either.prototype.toResult = function toResult() { | ||
return Either.toResult(this); | ||
}; | ||
// toTask :: Either a b ~> Maybe b | ||
Either.prototype.toTask = function toTask() { | ||
return Either.toTask(this); | ||
}; | ||
// toValidation :: Either a b ~> Validation a b | ||
Either.prototype.toValidation = function toValidation() { | ||
return Either.toValidation(this); | ||
}; | ||
/* | ||
@@ -127,0 +179,0 @@ |------------------------------------------------------------------------------ |
53
maybe.js
const FL = require('fantasy-land'); | ||
const Task = require('./task'); | ||
const Either = require('./either'); | ||
const Result = require('./result'); | ||
const Validation = require('./validation'); | ||
const { union } = require('./adt'); | ||
@@ -77,3 +82,31 @@ const { __, curry, always, compose } = require('./_tools'); | ||
// toEither :: Maybe b -> Either a b | ||
Maybe.toEither = maybe => | ||
maybe.cata({ | ||
Nothing: Either.Left, | ||
Just: Either.Right, | ||
}); | ||
// toResult :: Maybe b -> Result a b | ||
Maybe.toResult = maybe => | ||
maybe.cata({ | ||
Nothing: Result.Err, | ||
Just: Result.Ok, | ||
}); | ||
// toValidation :: Maybe b -> Validation a b | ||
Maybe.toValidation = maybe => | ||
maybe.cata({ | ||
Nothing: Validation.Failure, | ||
Just: Validation.Success, | ||
}); | ||
// toTask :: Maybe b -> Task a b | ||
Maybe.toTask = maybe => | ||
maybe.cata({ | ||
Nothing: Task.reject, | ||
Just: Task.of, | ||
}); | ||
/* | ||
@@ -130,3 +163,23 @@ |------------------------------------------------------------------------------ | ||
// toEither :: Maybe b ~> Either a b | ||
Maybe.prototype.toEither = function toEither() { | ||
return Maybe.toEither(this); | ||
}; | ||
// toResult :: Maybe b ~> Result a b | ||
Maybe.prototype.toResult = function toResult() { | ||
return Maybe.toResult(this); | ||
}; | ||
// toValidation :: Maybe b ~> Validation a b | ||
Maybe.prototype.toValidation = function toValidation() { | ||
return Maybe.toValidation(this); | ||
}; | ||
// toTask :: Maybe b ~> Maybe b | ||
Maybe.prototype.toTask = function toTask() { | ||
return Maybe.toTask(this); | ||
}; | ||
/* | ||
@@ -133,0 +186,0 @@ |------------------------------------------------------------------------------ |
{ | ||
"name": "zoomjs", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"description": "Helpful abstractions for functional programming in javascript.", | ||
@@ -9,2 +9,3 @@ "main": "index.js", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"lint": "bin/lint", | ||
@@ -18,3 +19,4 @@ "tdd": "bin/tdd", | ||
"conventional-changelog-cli": "^1.3.2", | ||
"eslint": "^3.19.0", | ||
"coveralls": "^3.0.12", | ||
"eslint": ">=4.18.2", | ||
"eslint-config-airbnb-base": "^11.2.0", | ||
@@ -21,0 +23,0 @@ "eslint-plugin-import": "^2.6.1", |
@@ -53,3 +53,3 @@ const FL = require('fantasy-land'); | ||
// andThen :: Reader e a ~> (a -> Reader e b) -> Reader e b | ||
Reader.prototype.andThen = Reader.prototype.andThen; | ||
Reader.prototype.andThen = Reader.prototype.chain; | ||
@@ -56,0 +56,0 @@ // map :: Reader e a ~> (a -> b) -> Reader e b |
# Zoom . js | ||
[![CircleCI](https://circleci.com/gh/dustinws/zoom/tree/master.svg?style=shield)](https://circleci.com/gh/dustinws/zoom/tree/master) | ||
[![npm version](https://badge.fury.io/js/zoomjs.svg)](https://badge.fury.io/js/zoomjs) | ||
[![deps](https://david-dm.org/dustinws/zoom.svg)](https://david-dm.org/dustinws/zoom.svg) | ||
[![Coverage Status](https://coveralls.io/repos/github/dustinws/zoom/badge.svg?branch=master)](https://coveralls.io/github/dustinws/zoom?branch=master) | ||
@@ -6,0 +8,0 @@ --- |
const FL = require('fantasy-land'); | ||
const Task = require('./task'); | ||
const Either = require('./either'); | ||
const Maybe = require('./maybe'); | ||
const Validation = require('./validation'); | ||
const { union } = require('./adt'); | ||
@@ -60,3 +65,31 @@ const { __, curry, always, compose } = require('./_tools'); | ||
// toMaybe :: Result a b -> Maybe b | ||
Result.toMaybe = result => | ||
result.cata({ | ||
Err: Maybe.Nothing.of, | ||
Ok: Maybe.Just.of, | ||
}); | ||
// toEither :: Result a b -> Either a b | ||
Result.toEither = result => | ||
result.cata({ | ||
Err: Either.Left.of, | ||
Ok: Either.Right.of, | ||
}); | ||
// toTask :: Result a b -> Task a b | ||
Result.toTask = result => | ||
result.cata({ | ||
Err: Task.reject, | ||
Ok: Task.of, | ||
}); | ||
// toValidation :: Result a b -> Validation a b | ||
Result.toValidation = result => | ||
result.cata({ | ||
Err: Validation.Failure.of, | ||
Ok: Validation.Success.of, | ||
}); | ||
/* | ||
@@ -113,2 +146,22 @@ |------------------------------------------------------------------------------ | ||
// toMaybe :: Result a b ~> Maybe b | ||
Result.prototype.toMaybe = function toMaybe() { | ||
return Result.toMaybe(this); | ||
}; | ||
// toEither :: Result a b ~> Either a b | ||
Result.prototype.toEither = function toEither() { | ||
return Result.toEither(this); | ||
}; | ||
// toTask :: Result a b ~> Task a b | ||
Result.prototype.toTask = function toTask() { | ||
return Result.toTask(this); | ||
}; | ||
// toValidation :: Result a b ~> Validation a b | ||
Result.prototype.toValidation = function toValidation() { | ||
return Result.toValidation(this); | ||
}; | ||
/* | ||
@@ -115,0 +168,0 @@ |------------------------------------------------------------------------------ |
const FL = require('fantasy-land'); | ||
const Task = require('./task'); | ||
const Either = require('./either'); | ||
const Maybe = require('./maybe'); | ||
const Result = require('./result'); | ||
const { union } = require('./adt'); | ||
@@ -80,3 +85,31 @@ const { __, curry, always, compose } = require('./_tools'); | ||
// toEither ::Validation a b -> Either a b | ||
Validation.toEither = validation => | ||
validation.cata({ | ||
Failure: Either.Left.of, | ||
Success: Either.Right.of, | ||
}); | ||
// toMaybe ::Validation a b -> Maybe b | ||
Validation.toMaybe = validation => | ||
validation.cata({ | ||
Failure: Maybe.Nothing.of, | ||
Success: Maybe.Just.of, | ||
}); | ||
// toResult ::Validation a b -> Result a b | ||
Validation.toResult = validation => | ||
validation.cata({ | ||
Failure: Result.Err.of, | ||
Success: Result.Ok.of, | ||
}); | ||
// toTask ::Validation a b -> Task a b | ||
Validation.toTask = validation => | ||
validation.cata({ | ||
Failure: Task.reject, | ||
Success: Task.of, | ||
}); | ||
/* | ||
@@ -146,2 +179,23 @@ |------------------------------------------------------------------------------ | ||
// toEither :: Validation a b ~> Either a b | ||
Validation.prototype.toEither = function toEither() { | ||
return Validation.toEither(this); | ||
}; | ||
// toMaybe :: Validation a b ~> Maybe b | ||
Validation.prototype.toMaybe = function toMaybe() { | ||
return Validation.toMaybe(this); | ||
}; | ||
// toResult :: Validation a b ~> Result a b | ||
Validation.prototype.toResult = function toResult() { | ||
return Validation.toResult(this); | ||
}; | ||
// toTask :: Validation a b ~> Task a b | ||
Validation.prototype.toTask = function toTask() { | ||
return Validation.toTask(this); | ||
}; | ||
/* | ||
@@ -148,0 +202,0 @@ |------------------------------------------------------------------------------ |
51641
1404
42
8