Coder Social home page Coder Social logo

bukk's Introduction

bukk 🐐

Functional programming for Norwegians ⛷️

npm module Coverage Status Build Status Dependencies devDependencies Status

Why?

Not exactly. Well, not only for Norwegians. Inspired by Ramda, this an automatically curried, data-last, functional JavaScript library.

Goals and philosophies

  • Declarative code
    Much favored over "smart" code. As an example it is preferred to use existing higher-order functions like Array.prototype.every() instead of reimplementing similar logic using loops.

  • Predictable behaviors
    B.map(B.inc, 1) should return 2. Not [], [undefined] or [2]. Just 2.

  • ES6 compliant
    It is totally fine to do B.map(B.inc, new Set([1, 2, 3])). This will simply return Set {2, 3, 4}.

  • Feature-rich
    As seen above, B.map knows how to handle Sets. Similarly, other B functions that can operate on Arrays, typically knows how to operate on other data structures as well.

  • No dependencies

  • Great code coverage

Examples

const incCollection = B.map(B.inc)

incCollection([1, 2, 3])
// => [2, 3, 4]

incCollection(new Set([1, 2, 3]))
// => Set {2, 3, 4}
const isFoo = B.equals('foo')
const allIsFoo = B.all(isFoo)

allIsFoo({x: 'foo', y: 'foo', z: 'foo'})
// => true

allIsFoo(['foo', 'bar', 'baz'])
// => false
const takeTwo = B.take(2)

takeTwo(new Map([[1, 'a'], [2, 'b'], [3, 'c']]))
// => Map { 1 => 'a', 2 => 'b' }

takeTwo('foobar')
// => 'fo'
const double = B.multiply(2)
const addFive = B.add(5)
const incDoubleAndAddFive = B.compose(addFive, double, B.inc)

incDoubleAndAddFive(1)
// => 9
const sqrtOfProduct = B.pipe(B.multiply, Math.sqrt)

sqrtOfProduct(3, 12)
// => 6
const multiplyThree = (a, b, c) => a * b * c
const multiplyThreeCurried = B.curry(multiplyThree)

multiplyThreeCurried(2)
// => Function

multiplyThreeCurried(2)(3)
multiplyThreeCurried(2, 3)
// => Function

multiplyThreeCurried(2)(3)(4)
multiplyThreeCurried(2, 3)(4)
multiplyThreeCurried(2)(3, 4)
// => 24

Installation

Install using yarn:

yarn add bukk

Or npm:

npm install --save bukk

Usage

Import module:

import * as B from 'bukk'
import { compose, map, prop } from 'bukk'

Or add the B variable to the global scope:

<script src="nodule_modules/bukk/dist/bukk.js"></script>

Development

Install dependencies:

yarn install

Build:

yarn run build

Will lint the source code, run tests and generate code coverage, and build a minified version of the library.

Running tests

Test once:

yarn run test

Test in watch mode:

yarn run dev

Reading coverage reports:

yarn run report

"Bukk"?

"Bukk" means "ram" in Norwegian :)

API

B.add

Number --> Number --> Number


B.all

(* --> Boolean) --> Array | Map | Object | Set | String --> Boolean


B.and

a --> b --> a | b


B.any

(* --> Boolean) --> Array | Map | Object | Set | String --> Boolean


B.append

* --> Array | Map | Set | String --> Array | Map | Set | String


B.both

(*... --> b) --> (*... --> d) --> b | d


B.compose

Function... --> Function


B.concat

Array | Map | Set | String --> Array | Map | Set | String --> Array | Map | Set | String


B.curry

Function --> Function


B.dec

Number --> Number


B.divide

Number --> Number --> Number


B.either

(*... --> b) --> (*... --> d) --> b | d


B.equals

* --> * --> Boolean


B.filter

(* --> Boolean) --> Array | Map | Object | Set | String --> Array | Map | Object | Set | String


B.find

(* --> Boolean) --> Array | Map | Object | Set | String --> *


B.flatten

Array --> Array


B.gt

Number --> Number --> Boolean


B.gte

Number --> Number --> Boolean


B.head

Array | Map | Set | String --> *


B.inc

Number --> Number


B.init

Array | Map | Set | String --> Array | Map | Set | String


B.kind

* --> String


B.last

Array | Map | Set | String --> *


B.lt

Number --> Number --> Boolean


B.lte

Number --> Number --> Boolean


B.map

Function --> * --> *


B.max

Number --> Number --> Number


B.merge

Object --> Object --> Object


B.min

Number --> Number --> Number


B.multiply

Number --> Number --> Number


B.none

(* --> Boolean) --> Array | Map | Object | Set | String --> Boolean


B.or

a --> b --> a | b


B.pipe

Function... --> Function


B.prepend

* --> Array | Map | Set | String --> Array | Map | Set | String


B.prop

String --> Object --> *


B.range

Number --> Number --> Array


B.reduce

(a --> b --> a) --> a --> Array | Map | Object | Set | String --> a


B.reject

(* --> Boolean) --> Array | Map | Object | Set | String --> Array | Map | Object | Set | String


B.reverse

Array | Map | Set | String --> Array | Map | Set | String


B.slice

Number --> Number --> Array | Map | Set | String --> Array | Map | Set | String


B.sortBy

Function --> Array | Map | Set --> Array | Map | Set


B.subtract

Number --> Number --> Number


B.tail

Array | Map | Set | String --> Array | Map | Set | String


B.take

Number --> Array | Map | Set | String --> Array | Map | Set | String


B.trim

String --> String


B.type

* --> String


B.zip

Array --> Array --> Array

bukk's People

Contributors

christianhg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bukk's Issues

Rename B.type to B.kind

B.type does not return the type of the argument. It returns the [[Class]]. The name B.type could lead to confusion. B.class however would be an unfortunate name thus B.kind is more fitting.

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.