4.5 Extending Promise to Functor
https://github.com/eu81273/jsfiddle-console
by dimitrs_papadimitriou
HTML
<script src="https://rawgit.com/eu81273/jsfiddle-console/master/console.js"></script>
JavaScript
var fetchClientsMock = () =>
[{ id: 1, name: 'jim', age: 29 },
{ id: 2, name: 'jane', age: 25 }]
var clientRepository = ({
getById: (id) =>
fetchClientsMock().find(c => c.id == id)
});
var client = clientRepository .getById(1);
if(client){
console.log(`the client name is ${client.name}`)
}
else{
console.log(`there is no client with that id `)
}