Skip to content

Commit 6c38148

Browse files
committed
This is partial, not curry
1 parent fd58160 commit 6c38148

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

JavaScript/1-simple.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
'use strict';
22

3-
const curry = (fn, x) => (...args) => fn(x, ...args);
3+
const partial = (fn, ...args) => (...rest) => fn(...args.concat(rest));
44

5-
const projection = (fields, obj) => (
6-
Object.keys(obj)
7-
.filter(field => fields.includes(field))
8-
.reduce((hash, key) => (hash[key] = obj[key], hash), {})
9-
);
5+
const projection = (fields, obj) => Object.keys(obj)
6+
.filter(field => fields.includes(field))
7+
.reduce((hash, key) => (hash[key] = obj[key], hash), {});
108

119
// Dataset
1210

@@ -20,8 +18,8 @@ const persons = [
2018

2119
// Usage
2220

23-
const p1 = curry(projection, ['name', 'born']);
24-
const p2 = curry(projection, ['name']);
21+
const p1 = partial(projection, ['name', 'born']);
22+
const p2 = partial(projection, ['name']);
2523

2624
const data = persons.map(p1).map(p2);
2725
console.dir(data);

JavaScript/2-extended.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
'use strict';
22

3-
const curry = (fn, x) => (...args) => fn(x, ...args);
3+
const partial = (fn, ...args) => (...rest) => fn(...args.concat(rest));
44

55
// Projection
66

7-
const projection = (meta, obj) => (
8-
Object.keys(meta).reduce((hash, key) => (
7+
const projection = (meta, obj) => Object.keys(meta)
8+
.reduce((hash, key) => (
99
hash[key] = meta[key].reduce(
1010
(val, fn, i) => (i === 0 ? obj[fn] : fn(val)), null
1111
), hash
12-
), {})
13-
);
12+
), {});
1413

1514
// Dataset
1615

@@ -34,6 +33,6 @@ const md = {
3433

3534
// Usage
3635

37-
const p1 = curry(projection, md);
36+
const p1 = partial(projection, md);
3837
const data = persons.map(p1);
3938
console.dir(data);

0 commit comments

Comments
 (0)