Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- import Maybe from 'maybe';
- import R from 'ramda';
- var person = {
- 'name' : 'Homer Simpson',
- 'address' : {
- 'street' : '123 Fake St.',
- 'city' : 'Springfield'
- },
- age : 20
- };
- const state = x => x.state;
- const address = x => x.address;
- const toUpper = ''.toUpperCase;
- const toLower = ''.toLowerCase;
- const concat = [].concat;
- const age = x => x.age;
- const personsState = Maybe.of( person )
- .map( address )
- .map( state )
- .map( toUpper )
- .map( toLower );
- console.log( personsState );
- const newAge = Maybe.of( person )
- .map( age )
- .map( R.add( 5 ) )
- .map( R.multiply( 10 ) );
- console.log( newAge );
- const anotherWay = R.map( R.compose( R.add( 5 ), age ) );
- console.log( anotherWay( Maybe.of( person ) ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement