Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "liftjs", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"homepage": "https://github.com/atomable/lift.js/", | ||
@@ -5,0 +5,0 @@ "description": "lift.js is a compact monad opinionated javascript library", |
@@ -5,3 +5,3 @@ # lift.js | ||
## Introduction | ||
lift.js is a compact monad opinionated javascript library. It implements Just, Maybe, Validation(Valid) and a nice Monad factory. The unit comes with a lift function so you can add functionnality later in code to your monad. It's ment to be flexible and faster to use. It's written with es6 so it's less than 100 lines. | ||
lift.js is a compact monad opinionated javascript library. It implements Just (Identity), Maybe, Valid (Validation) and a nice Monad factory. The unit comes with a lift function so you can add functionnality later in code to your monad. It's ment to be flexible and faster to use. It's written with es6 so it's less than 100 lines. | ||
@@ -11,3 +11,3 @@ ## Installation | ||
#### npm | ||
#### [npm](https://www.npmjs.com/package/liftjs) | ||
``` | ||
@@ -19,8 +19,27 @@ npm install liftjs | ||
With the `lift` function you can add function at any time on the monads. | ||
```javascript | ||
const justWithLog = Just(5).lift('log',console.log); | ||
justWithValue.log(); | ||
lift(name, func); | ||
``` | ||
```javascript | ||
const justWithLog = Just(5); | ||
Just.lift('log', value => should(value).equal(5)); | ||
justWithLog.log(); | ||
// console> 5 | ||
``` | ||
You can also use it on your custom monads. | ||
```javascript | ||
const Person = Monad(); | ||
const person = Person({ firstname: 'Bill', lastname: 'Murray' }); | ||
const FullName = Monad(); | ||
Person.lift('compose', person => FullName(`${person.firstname}, ${person.lastname}`)); | ||
person.compose().run(console.log); | ||
// console> Bill, Murray | ||
``` | ||
## All Monads | ||
@@ -33,3 +52,4 @@ | ||
bind(func, args) | ||
``` | ||
```javascript | ||
const justWithValue = Just(5).bind((value)=> Just(value)); | ||
@@ -42,3 +62,4 @@ | ||
of(value) | ||
``` | ||
```javascript | ||
const justWithValue = Just(5).of(6); | ||
@@ -53,3 +74,4 @@ // Just[6] | ||
get() | ||
``` | ||
```javascript | ||
const value = Just(5).get(); | ||
@@ -62,3 +84,4 @@ //5 | ||
map(func) | ||
``` | ||
```javascript | ||
const justWithValue = Just(7).map(value => value * 2); | ||
@@ -71,3 +94,4 @@ // Just[14] | ||
join() | ||
``` | ||
```javascript | ||
const justWithValue = Just(Just(5)).join() | ||
@@ -79,3 +103,4 @@ // Just[5] | ||
toMaybe() | ||
``` | ||
```javascript | ||
const maybeWithValue = Just(5).toMaybe(); | ||
@@ -88,3 +113,4 @@ // Maybe[5] | ||
run(func) | ||
``` | ||
```javascript | ||
Just(5).run(value => console.log(value)); | ||
@@ -99,3 +125,4 @@ // console> 5 | ||
none() | ||
``` | ||
```javascript | ||
const maybeWithValue = Maybe().none() | ||
@@ -120,3 +147,4 @@ // Maybe[] | ||
isNone() | ||
``` | ||
```javascript | ||
const value = Maybe(5).isNone(); | ||
@@ -129,3 +157,4 @@ // false | ||
isJust() | ||
``` | ||
```javascript | ||
const value = Maybe(5).isJust(); | ||
@@ -138,3 +167,4 @@ // true | ||
orJust() | ||
``` | ||
```javascript | ||
const maybeWithValue = Maybe().orJust(15); | ||
@@ -147,3 +177,4 @@ // Maybe[15] | ||
orElse(monad) | ||
``` | ||
```javascript | ||
const maybeWithValue = Maybe(5).orElse(Maybe(15)); | ||
@@ -159,3 +190,3 @@ // Maybe[5] | ||
- [npm](https://www.npmjs.com/package/liftjs) | ||
- [@atomable](https://twitter.com/atomable) | ||
- [atomable](https://twitter.com/atomable) | ||
- [@pre63](http://twitter.com/pre63) | ||
@@ -165,7 +196,7 @@ | ||
Written and maintained by [@pre63](http://twitter.com/pre63). | ||
Written and maintained by [pre63](http://twitter.com/pre63). | ||
Sponsored by [@atomable](https://twitter.com/atomable). | ||
Sponsored by [atomable](https://atomable.io). | ||
Based on [Douglas Crockford MONAD](https://github.com/douglascrockford/monad/blob/master/monad.js). | ||
Special tanks to [Monet](https://github.com/cwmyers/monet.js) for the inspiration and a bunch of tests. | ||
Special thanks to [Monet](https://github.com/cwmyers/monet.js) for the inspiration. |
@@ -17,2 +17,12 @@ /* jshint -W097, esversion: 6, strict: true, node: true */ | ||
}); | ||
it ('peron test', () => { | ||
const Person = Monad(); | ||
const person = Person({ firstname: 'Bill', lastname: 'Murray' }); | ||
const FullName = Monad(); | ||
Person.lift('compose', person => FullName(`${person.firstname}, ${person.lastname}`)); | ||
person.compose().run(console.log); | ||
}); | ||
}); | ||
@@ -19,0 +29,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25935
461
185