Comparing version 0.3.0 to 0.4.0
module.exports = { | ||
add: require('./src/add'), | ||
all: require('./src/all'), | ||
and: require('./src/and'), | ||
any: require('./src/any'), | ||
compose: require('./src/compose'), | ||
curry: require('./src/curry'), | ||
equals: require('./src/equals'), | ||
flatten: require('./src/flatten'), | ||
@@ -7,0 +10,0 @@ gt: require('./src/gt'), |
{ | ||
"name": "bukk", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "christianhg/bukk", |
@@ -9,7 +9,7 @@ # bukk | ||
## How is this better than ramda? | ||
### How is this better than ramda? | ||
It's not. It exists mainly for the purpose of letting its author get more experienced with functional programming. | ||
## "Bukk"? | ||
### "Bukk"? | ||
@@ -38,2 +38,13 @@ "Bukk" means "ram" in Norwegian. | ||
### Example | ||
```js | ||
const inc = B.add(1) | ||
const incList = B.map(inc) | ||
incList([1, 2, 3]) | ||
// ==> [2, 3, 4] | ||
``` | ||
## Development | ||
@@ -40,0 +51,0 @@ |
const curry = require('./curry') | ||
const type = require('./type') | ||
const map = (f, a) => | ||
({ | ||
const map = (f, a) => { | ||
const m = { | ||
'Array': () => a.map(f), | ||
'Boolean': () => f(a), | ||
'Map': () => new Map(Array.from(a).map(([key, value]) => [key, f(value)])), | ||
'Null': () => null, | ||
'Number': () => f(a), | ||
'Object': () => Object.keys(a).reduce((b, key) => { | ||
@@ -16,7 +13,7 @@ b[key] = f(a[key]) | ||
'Set': () => new Set([...a].map(f)), | ||
'String': () => f(a), | ||
'Symbol': () => a, | ||
'Undefined': () => undefined | ||
}[type(a)]()) | ||
'*': () => f(a) | ||
} | ||
return (m[type(a)] || m['*'])() | ||
} | ||
module.exports = curry(map) |
@@ -6,18 +6,30 @@ import test from 'ava' | ||
test('should export add', t => { | ||
test('should export B.add', t => { | ||
t.is(type(B.add), 'Function') | ||
}) | ||
test('should export and', t => { | ||
test('should export B.all', t => { | ||
t.is(type(B.all), 'Function') | ||
}) | ||
test('should export B.and', t => { | ||
t.is(type(B.and), 'Function') | ||
}) | ||
test('should export compose', t => { | ||
test('should export B.any', t => { | ||
t.is(type(B.any), 'Function') | ||
}) | ||
test('should export B.compose', t => { | ||
t.is(type(B.compose), 'Function') | ||
}) | ||
test('should export curry', t => { | ||
test('should export B.curry', t => { | ||
t.is(type(B.curry), 'Function') | ||
}) | ||
test('should export B.equals', t => { | ||
t.is(type(B.equals), 'Function') | ||
}) | ||
test('should export B.flatten', t => { | ||
@@ -27,23 +39,23 @@ t.is(type(B.flatten), 'Function') | ||
test('should export gt', t => { | ||
test('should export B.gt', t => { | ||
t.is(type(B.gt), 'Function') | ||
}) | ||
test('should export gte', t => { | ||
test('should export B.gte', t => { | ||
t.is(type(B.gte), 'Function') | ||
}) | ||
test('should export head', t => { | ||
test('should export B.head', t => { | ||
t.is(type(B.head), 'Function') | ||
}) | ||
test('should export lt', t => { | ||
test('should export B.lt', t => { | ||
t.is(type(B.lt), 'Function') | ||
}) | ||
test('should export lte', t => { | ||
test('should export B.lte', t => { | ||
t.is(type(B.lte), 'Function') | ||
}) | ||
test('should export map', t => { | ||
test('should export B.map', t => { | ||
t.is(type(B.map), 'Function') | ||
@@ -56,7 +68,7 @@ }) | ||
test('should export or', t => { | ||
test('should export B.or', t => { | ||
t.is(type(B.or), 'Function') | ||
}) | ||
test('should export pipe', t => { | ||
test('should export B.pipe', t => { | ||
t.is(type(B.pipe), 'Function') | ||
@@ -69,3 +81,3 @@ }) | ||
test('should export slice', t => { | ||
test('should export B.slice', t => { | ||
t.is(type(B.slice), 'Function') | ||
@@ -78,8 +90,8 @@ }) | ||
test('should export tail', t => { | ||
test('should export B.tail', t => { | ||
t.is(type(B.tail), 'Function') | ||
}) | ||
test('should export type', t => { | ||
test('should export B.type', t => { | ||
t.is(type(B.type), 'Function') | ||
}) |
@@ -34,16 +34,2 @@ import test from 'ava' | ||
test('should not map Null', t => { | ||
t.deepEqual(map(inc, null), null) | ||
}) | ||
test('should not map a Symbol', t => { | ||
const one = Symbol(1) | ||
t.deepEqual(map(inc, one), one) | ||
}) | ||
test('should not map Undefined', t => { | ||
t.deepEqual(map(inc, undefined), undefined) | ||
}) | ||
test('should map a Map', t => { | ||
@@ -50,0 +36,0 @@ t.deepEqual( |
138088
43
521
69