22
33const curry = ( fn , x ) => ( ...args ) => fn ( x , ...args ) ;
44
5+ const projection = ( meta , obj ) => (
6+ Object . keys ( meta ) . reduce ( ( hash , key ) => (
7+ hash [ key ] = meta [ key ] . reduce (
8+ ( val , fn , i ) => ( i === 0 ? obj [ fn ] : fn ( val ) ) , null
9+ ) , hash
10+ ) , { } )
11+ ) ;
12+
13+ const upper = ( s ) => (
14+ typeof ( s ) === 'string' ? s . toUpperCase ( ) : ''
15+ ) ;
16+
17+ const age = ( year ) => (
18+ new Date ( ) . getFullYear ( ) - new Date ( year + '' ) . getFullYear ( )
19+ ) ;
20+
21+ // Dataset
22+
523const persons = [
624 { name : 'Marcus Aurelius' , city : 'Rome' , born : 121 } ,
725 { name : 'Victor Glushkov' , city : 'Rostov on Don' , born : 1923 } ,
@@ -10,28 +28,15 @@ const persons = [
1028 { name : 'Rene Descartes' , city : 'La Haye en Touraine' , born : 1596 }
1129] ;
1230
31+ // Metadata
32+
1333const md = {
1434 name : [ 'name' ] ,
1535 place : [ 'city' , upper , s => '<' + s + '>' ] ,
1636 age : [ 'born' , age ]
1737} ;
1838
19- const projection = ( meta , obj ) => (
20- Object . keys ( meta ) . reduce ( ( hash , key ) => (
21- hash [ key ] = meta [ key ] . reduce (
22- ( val , fn , i ) => ( i === 0 ? obj [ fn ] : fn ( val ) ) , null
23- ) , hash
24- ) , { } )
25- ) ;
2639
2740const p1 = curry ( projection , md ) ;
2841const data = persons . map ( p1 ) ;
2942console . dir ( data ) ;
30-
31- function upper ( s ) {
32- return typeof ( s ) === 'string' ? s . toUpperCase ( ) : '' ;
33- }
34-
35- function age ( year ) {
36- return new Date ( ) . getFullYear ( ) - new Date ( year + '' ) . getFullYear ( ) ;
37- }
0 commit comments