Functional Programming in JavaScript (Functional Programming with JavaScript and React Book 4) by Salcescu Cristian

Functional Programming in JavaScript (Functional Programming with JavaScript and React Book 4) by Salcescu Cristian

Author:Salcescu, Cristian [Salcescu, Cristian]
Language: eng
Format: epub, pdf
Published: 2020-08-07T16:00:00+00:00


function M(value){

function map(f){

const newValue = f(value);

return M(newValue);

}

function bind(f){

const newValue = f(value);

return newValue;

}

return {

map,

bind

}

}

function unit(value){

return M(value);

}

return {

unit

}

})();

unit creates a new monad wrapping a value.

bind defines the flat map operation.

Here is how the monad can be created and used.

import M from './M';

function f(){

return M.unit(2)

}

M.unit(1).bind(f)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.