Git Product home page Git Product logo

funkel's Introduction

Funkel

Simple and lightweight functional toolset inspired by Clojure using import.

Getting Started

Use import to bring in the necessary functions into your module. In the following example we're going to import the partial function and utilise it!

import {partial} from 'funkel';

const addNumbers = (a, b) => a + b;
const addTwo     = partial(addNumbers, 2);

expect(addTwo(3)).toEqual(5);

Releases

๐Ÿ“ฆ v0.1.x

  • identity(a)
  • trace(a)
  • curry(fn)
  • partial(fn, ...a)
  • compose(...fns)
  • composeDeferred(...fns)

Examples

Below are a set of examples for using Funkel โ€“ although it's not an exhaustive list, and you should refer to the source and/or associated unit-tests if you need further information about what Funkel provides and how it functions.

trace

If you have a composed function but are having troubles, it's useful to console.log the current value at any given step, for these cases use trace in the compose function:

const pay = compose(printInvoice, f.trace, sendMoney, createOrder);

Promise-Safe Composing

For cases where you have functions that return promises, you can use the composeDeferred function.

import {composeDeferred} from 'funkel';

const addOne   = a => new Promise(resolve => resolve(a + 1));
const addTwo   = a => a + 2;
const addThree = a => new Promise(resolve => resolve(a + 3));

const composedFn = composeDeferred(addOne, addTwo, addEleven);

composedFn(0).then(result => {
    expect(result).toEqual(6);
});

funkel's People

Contributors

wildhoney avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

funkel's Issues

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.