File tree Expand file tree Collapse file tree 2 files changed +11
-14
lines changed
Expand file tree Collapse file tree 2 files changed +11
-14
lines changed Original file line number Diff line number Diff line change 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
2624const data = persons . map ( p1 ) . map ( p2 ) ;
2725console . dir ( data ) ;
Original file line number Diff line number Diff line change 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 ) ;
3837const data = persons . map ( p1 ) ;
3938console . dir ( data ) ;
You can’t perform that action at this time.
0 commit comments