Giter Site home page Giter Site logo

fun's Introduction

fun.js

Functional javascript library Fork on Github

Build Status Test Coverage Code Climate GitHub file size in bytes

Check bundle size on bundlephobia

Install fun.js

$ npm install fun.js --save

Docs

The documentation is done using jsdocs and can be found in the /docs folder or at the url https://astuanax.github.io/fun/

Functional library?

The fun.js is a functional library which supports monads and follows mostly he ramda specifications but tries to keep the bite size down. The focus is to provide helpful functions for react development with a small footprint.

Autocurried ?

Most if not all functions are autocurried, which means they can have any arity and you can still use default parameters in your function parameters.

Neat.

const abc = curry((a, b, c = [1, 2, 3]) => concat(a, b, c))

const add1 = abc(['tss tss'])
add1(['check']) // ['tss tss', 'check', 1, 2, 3]

Examples

Returning the sum of the length of all the arrays in an array

const lengthDeep = compose(sum, map(x => x.length))
const lengthDeep2 = fold((total, xs) => total + xs.length, 0)
    
const mapReduce = curry((m, r) => (x, y) => r(x, m(y)))

const deepLength = xs => fold(mapReduce(x => x.length, add), 0, xs)

lengthDeep([[1], [2, 3], [4, 5, 6]]) === 6

Adds a number to al values of an object

  const mapReduce = curry((m, r) => (x, y) => r(x, m(y)))

  const omap = curry((f, o) => fold(mapReduce(k => ({ [k]: f(o[k]) }), Object.assign), {}, keys(o)))
  const omapAdd10 = omap(add(10))
  omapAdd10({ a: 1, b: 2, c: 3 })) == { 'a': 11, 'b': 12, 'c': 13 }

Get the difference between 2 dates in seconds

const diffInSeconds = compose(toSeconds, diffDate)
const date1 = new Date('1999-12-31')
const date2 = new Date('2000-01-01')
   
diffInSeconds(date1, date2)) === -86400

Other libraries

The fun.js library is used together with some other libraries:

Matrix applicative providing standard matrix operations

Machine learning with functional undertones: perceptron, neural network and decision trees.

WIP React library with helper function

fun's People

Contributors

astuanax avatar dependabot[bot] avatar

Stargazers

 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.