Functional programming for Norwegians ⛷️
npm install bukk> Functional programming for Norwegians ⛷️





- Why?
- Goals and philosophies
- Examples
- Installation
- Usage
- Development
- "Bukk"?
- API
Not exactly. Well, not only for Norwegians. Inspired by Ramda, this an automatically curried, data-last, functional JavaScript library.
- 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 behaviorsB.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.
``js
const incCollection = B.map(B.inc)
incCollection([1, 2, 3])
// => [2, 3, 4]
incCollection(new Set([1, 2, 3]))
// => Set {2, 3, 4}
`
`js
const isFoo = B.equals('foo')
const allIsFoo = B.all(isFoo)
allIsFoo({x: 'foo', y: 'foo', z: 'foo'})
// => true
allIsFoo(['foo', 'bar', 'baz'])
// => false
`
`js
const takeTwo = B.take(2)
takeTwo(new Map([[1, 'a'], [2, 'b'], [3, 'c']]))
// => Map { 1 => 'a', 2 => 'b' }
takeTwo('foobar')
// => 'fo'
`
`js
const double = B.multiply(2)
const addFive = B.add(5)
const incDoubleAndAddFive = B.compose(addFive, double, B.inc)
incDoubleAndAddFive(1)
// => 9
`
`js
const sqrtOfProduct = B.pipe(B.multiply, Math.sqrt)
sqrtOfProduct(3, 12)
// => 6
`
`js
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
`
Install using yarn:
`bash`
yarn add bukk
Or npm:
`bash`
npm install --save bukk
Import module:
`js`
import * as B from 'bukk'
`js`
import { compose, map, prop } from 'bukk'
Or add the B variable to the global scope:
`html`
Install dependencies:
`bash`
yarn install
Build:
`bash`
yarn run build
Will lint the source code, run tests and generate code coverage, and build a minified version of the library.
Test once:
`bash`
yarn run test
Test in watch mode:
`bash`
yarn run dev
Reading coverage reports:
`bash`
yarn run report
"Bukk" means "ram" in Norwegian :)
Number --> Number --> Number
---
(* --> Boolean) --> Array | Map | Object | Set | String --> Boolean
---
a --> b --> a | b
---
(* --> Boolean) --> Array | Map | Object | Set | String --> Boolean
---
* --> Array | Map | Set | String --> Array | Map | Set | String
---
(... --> b) --> (... --> d) --> b | d
---
Function... --> Function
---
Array | Map | Set | String --> Array | Map | Set | String --> Array | Map | Set | String
---
Function --> Function
---
Number --> Number
---
Number --> Number --> Number
---
(... --> b) --> (... --> d) --> b | d
---
--> --> Boolean
---
(* --> Boolean) --> Array | Map | Object | Set | String --> Array | Map | Object | Set | String
---
( --> Boolean) --> Array | Map | Object | Set | String -->
---
Array --> Array
---
Number --> Number --> Boolean
---
Number --> Number --> Boolean
---
Array | Map | Set | String --> *
---
Number --> Number
---
Array | Map | Set | String --> Array | Map | Set | String
---
* --> String
---
Array | Map | Set | String --> *
---
Number --> Number --> Boolean
---
Number --> Number --> Boolean
---
Function --> -->
---
Number --> Number --> Number
---
Object --> Object --> Object
---
Number --> Number --> Number
---
Number --> Number --> Number
---
(* --> Boolean) --> Array | Map | Object | Set | String --> Boolean
---
a --> b --> a | b
---
Function... --> Function
---
* --> Array | Map | Set | String --> Array | Map | Set | String
---
String --> Object --> *
---
Number --> Number --> Array
---
(a --> b --> a) --> a --> Array | Map | Object | Set | String --> a
---
(* --> Boolean) --> Array | Map | Object | Set | String --> Array | Map | Object | Set | String
---
Array | Map | Set | String --> Array | Map | Set | String
---
Number --> Number --> Array | Map | Set | String --> Array | Map | Set | String
---
Function --> Array | Map | Set --> Array | Map | Set
---
Number --> Number --> Number
---
Array | Map | Set | String --> Array | Map | Set | String
---
Number --> Array | Map | Set | String --> Array | Map | Set | String
---
String --> String
---
* --> String
---
Array --> Array --> Array`