Giter VIP home page Giter VIP logo

es6-monads's Introduction

es6-monads

Playing around with the monads Maybe and Either and their functors Just, Nothing, Left and Right. This might help to prevent bugs during runtime. As some of you might already guess, this is inspired by Erlang and Elm ;)

Playing around with it:

// Using require instead of import, because it is supported in
// my atom editor with the script plugin, which allows me
// to simply press cmd i to run all of this without babel etc
const Maybe = require('./Maybe.js')
const Either = require('./Either.js')

// some random functions, which are not important
// and are just here to play around with them below
const times = nums => nums.reduce((a, b) => a * b, 1)
const double = a => a * 2
const quarter = a => a / 4
const pretty = a => `The value is ${a}!`

// Composing the functions together
const timesDoubleQuarterPretty = arr => 
    Maybe(times(arr))
        .fmap(double)
        .fmap(quarter)
        .fmap(pretty)

// Imagine because of some bug our input array is broken,
// but the code still runs fine, the Maybe returned a Nothing wrapper
const broken = [1, 2, 'x', 3, 4]
const result1 = timesDoubleQuarterPretty(broken) // Nothing

// The second input array is intact and the Maybe returns a Just wrapper
const intact = [1, 2, 3, 4]
const result2 = timesDoubleQuarterPretty(intact) // Just 'The value is 12!'

// And here we can simply use Either to pick the valid one
// Either returns the Left or Right functor which both have the .value method
const result = Either(result1, result2) // Right 'The value is 12!'
result.value() // 'The value is 12!'

I would love feedback! Please tell me if I'm not correctly understanding this stuff by writing an issue or sending me a tweet @KimHogeling

es6-monads's People

Contributors

kimhogeling avatar

Stargazers

 avatar Daniel Broadhurst avatar Nicolas Takashi avatar Mark Knight avatar Muriel Silveira avatar Sebastian avatar Josh Burgess avatar Sibelius Seraphini avatar Geoff Miller avatar

Watchers

James Cloos avatar

Forkers

suissa

es6-monads's Issues

Add job statuses to dashboard

User story

As a user
I want to see job statuses in the dashboard
so that I can see when my jobs are finished.

Acceptance criteria

Scenario 1

Given a new job is started/finished,
when the user opens the dashboard,
then the user should see the status of this job.

Scenario 2

Given the bla new job is started kleid,
when the user opens the dashboard,
then the user should bla bli blub hose.

Scenario 3

Given the bla new job is started kleid,
when the user opens the dashboard,
then the user should bla bli blub hose.

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.