Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

liftjs

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

liftjs

lift.js is a compact monad opinionated javascript library

  • 1.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Weekly downloads
 
Created
Source

lift.js — Write less code.

Introduction

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 simple to use. It's written with es6 so it's less than 100 lines.

Installation

npm
npm install liftjs
importing

All the following work, pick your demon. lift.js can be required directly for es next project or you can use the lift-min.js for all legacy applications.

var lift = require('liftjs');

const lift = require('liftjs');

import lift from 'liftjs';

import { Monad, Just, Maybe, Valid } from 'liftjs';

Monad

Monad(modifier) : unit

lift (lifting)

With the lift function you can add function at any time on the monads.

lift(name, func);
const justWithLog = Just(5);
Just.lift('log', console.log);
justWithLog.log();
// console> 5

You can also use it on your custom monads.

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

Just

Just is an implementaion of the Identity monad. It's called Just because an 8 character variable is just too long.

The folowing function are available on Just, Maybe, Valid.

bind, alias: chain flatMap

bind(func, args)
const justWithValue = Just(5).bind((value)=> Just(value));

// Just[5]

of, alias: pure

of(value)
const justWithValue = Just(5).of(6);
// Just[6]

const justWithValue = Just(5).of(Just(6));
// Just[6]

get

get()
const value = Just(5).get();
//5

map

map(func)
const justWithValue = Just(7).map(value => value * 2);
// Just[14]

join

join()
const justWithValue = Just(Just(5)).join()
// Just[5]

toMaybe

toMaybe()
const maybeWithValue = Just(5).toMaybe();
// Maybe[5]

run

run(func)
Just(5).run(value => console.log(value));
// console> 5

Maybe

none, alias: nothing

none()
const maybeWithValue = Maybe().none()
// Maybe[]

const maybeWithValue = Maybe().nothing()
// Maybe[]

const maybeWithValue = Maybe()
// Maybe[]

const maybeWithValue = Maybe(undefined)
// Maybe[]

const maybeWithValue = Maybe(null)
// Maybe[]

isNone, alias: isNothing

isNone()
const value = Maybe(5).isNone();
// false

isJust, alias: orSome

isJust()
const value = Maybe(5).isJust();
// true

orJust, alias: orSome

orJust()
const maybeWithValue = Maybe().orJust(15);
// Maybe[15]

orElse

orElse(monad)
const maybeWithValue = Maybe(5).orElse(Maybe(15));
// Maybe[5]

const maybeWithValue = Maybe().orElse(Just(15));
// Just[15]

Roadmap

I don't plan on adding all the typical monads to the library, if you feel one should be added you are welcome to make a pull request or to fork. I'm thinking of Free, IO and List, but not sure yet. It will depend on what I use in my own projects.

Below are the things that I actually plan on doing. Soon.

  • document Valid
  • document lift_value function
  • document method function
  • ap function just Just and Maybe & tests
  • 1 character alias for all methods that are more than 3 characters. Per example: Just(5).b(v=> Just(v)).m(v => v * 2)
  • tests for lift functions

Author

Written and maintained by pre63.

Sponsored by atomable.

Based on Douglas Crockford MONAD.

Special thanks to Monet for the inspiration.

FAQs

Package last updated on 20 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc