Giter Club home page Giter Club logo

adt-state's Introduction

adt-state

Function based State algebraic data type for safe code

npm install adt-state

Examples

Applicative

const pipe = require('adt-state/Helpers/pipe');
const ap = require('adt-state/State/operators/ap');
const runWith = require('adt-state/State/runners/run-with');
const { get, of } = require('adt-state/State/factory/');

// add :: Number -> Number -> Number
const add = x => y => x + y;

// ofAdd :: State s (Number -> Number -> Number)
const ofAdd = of(add);

// getAdd :: State s a
const getAdd = get(add);

const res1 = pipe(
  ap(of(1)),
  ap(of(2)),
  runWith(5)
)(ofAdd);

console.log(res1) // [ Resultant 3, State 5 ]

const res2 = pipe(
  ap(of(1)),
  runWith(5)
)(getAdd);

 console.log(res2); // [ Resultant 6, State 5 ]

Getting State and mapping over the resultant

const pipe = require('adt-state/Helpers/pipe');
const get = require('adt-state/State/factory/get');
const map = require('adt-state/State/operators/map');
const runWith = require('adt-state/State/runners/run-with');

const res = pipe(
  map(x => x * 3),
  runWith(5)
)(get());

console.log(res); // [ Resultant 15, State 5 ]

adt-state's People

Contributors

franciscotln avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.