Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. 'use strict';
  2.  
  3. import Maybe from 'maybe';
  4. import R from 'ramda';
  5.  
  6. var person = {
  7. 'name' : 'Homer Simpson',
  8. 'address' : {
  9. 'street' : '123 Fake St.',
  10. 'city' : 'Springfield'
  11. },
  12. age : 20
  13. };
  14.  
  15. const state = x => x.state;
  16. const address = x => x.address;
  17. const toUpper = ''.toUpperCase;
  18. const toLower = ''.toLowerCase;
  19. const concat = [].concat;
  20. const age = x => x.age;
  21.  
  22. const personsState = Maybe.of( person )
  23. .map( address )
  24. .map( state )
  25. .map( toUpper )
  26. .map( toLower );
  27.  
  28. console.log( personsState );
  29.  
  30. const newAge = Maybe.of( person )
  31. .map( age )
  32. .map( R.add( 5 ) )
  33. .map( R.multiply( 10 ) );
  34.  
  35. console.log( newAge );
  36.  
  37. const anotherWay = R.map( R.compose( R.add( 5 ), age ) );
  38.  
  39. console.log( anotherWay( Maybe.of( person ) ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement