Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/lodash/lodash/3.10.1/lodash.min.js"></script>
<meta name="description" content="[FPJS | Luis Atencio | Monads]">
  <meta charset="utf-8">
  <title>FPJS | Luis Atencio | Monads</title>
  <script src="https://cdn.rawgit.com/luijar/functional-programming-js/master/src/lib/maybe.js"></script>
    <script src="https://cdn.rawgit.com/luijar/functional-programming-js/master/src/lib/either.js"></script>
</head>
<body>
</body>
</html>
 
/**
  Functional Programming in JavaScript
  @author Luis Atencio
  Monads
 */
// Curried adder
function add(a) {
   return function (b) {                   
      return a + b;
  }
}
// Mapping a valid object over a Maybe
var user = {name: 'Haskell Curry', age: 14};
var result = Maybe.fromNullable(user)
  .map(_.property('age'))
  .map(add(1));
console.log('Result: ' + result.toString());
// Mapping null over a Maybe
var result = Maybe.fromNullable(null)
  .map(_.property('age'))
  .map(add(1));
console.log('Result: ' + result.toString());
/*
 TODO: Produce the same program, using an Either.Right for the positive case, and a Either.Left for the negative case
 
 The outputs should be: 
 
 Either.Right(15)
 Either.Left(null)
*/
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
luijarpro
0viewers