-
Notifications
You must be signed in to change notification settings - Fork 86
/
into.spec.js
53 lines (47 loc) · 1.74 KB
/
into.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { into as intoRamda, map as mapRamda } from 'ramda';
import { add, always, compose, filter, identity, map, take } from '../rambda';
import { into } from './into';
const isOdd = (b) => b % 2 !== 0;
const addXf = {
'@@transducer/step': add,
'@@transducer/init': always(0),
'@@transducer/result': identity,
};
it.only('transduces into arrays', () => {
const result = intoRamda([10, 20], mapRamda(add(7)), [1, 2, 3, 4]);
console.log(result);
// expect(into([], mapRamda(add(1)), [1, 2, 3, 4])).toEqual([2, 3, 4, 5]);
// expect(into([], map(add(1)), [1, 2, 3, 4])).toEqual([2, 3, 4, 5])
// expect(into([], filter(isOdd), [1, 2, 3, 4])).toEqual([1, 3])
// expect(into([], compose(map(add(1)), take(2)), [1, 2, 3, 4])).toEqual([2, 3])
});
// it('transduces into strings', function () {
// expect(into('', map(add(1)), [1, 2, 3, 4])).toEqual('2345')
// expect(into('', filter(isOdd), [1, 2, 3, 4])).toEqual('13')
// expect(into('', compose(map(add(1)), take(2)), [1, 2, 3, 4])).toEqual('23')
// })
// it('transduces into objects', function () {
// expect(
// into({}, identity, [
// ['a', 1],
// ['b', 2],
// ])
// ).toEqual({ a: 1, b: 2 })
// expect(into({}, identity, [{ a: 1 }, { b: 2, c: 3 }])).toEqual({ a: 1, b: 2, c: 3 })
// })
// it('dispatches to objects that implement `reduce`', function () {
// var obj = {
// x: [1, 2, 3],
// reduce: function () {
// return 'override'
// },
// }
// expect(into([], map(add(1)), obj)).toEqual('override')
// expect(into([], filter(isOdd), obj)).toEqual('override')
// })
// it('allows custom transformer', function () {
// var intoSum = into(addXf)
// var add2 = map(add(2))
// var result = intoSum(add2)
// expect(result([1, 2, 3, 4])).toEqual(18)
// })