-
-
Save nonsensecreativity/56a225e088055562cac00cb7b65ca081 to your computer and use it in GitHub Desktop.
functional programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let add = (val, fun) => fun(val + 3); | |
| let multiplication = (val) => val * 3; | |
| console.log(add(2, multiplication)); | |
| //-------------------------------- | |
| let test = { | |
| a: 10, | |
| b: 20, | |
| c: 30 | |
| }; | |
| let loopMap = (obj) => { | |
| let o = {}; | |
| for (let prop in obj) { | |
| o[prop] = obj[prop] + 10; | |
| } | |
| return o; | |
| }; | |
| console.log('loopMap', loopMap(test)); | |
| //---------------------------------- | |
| let loopMap2 = (obj, fun) => { | |
| let o = {}; | |
| for (let prop in obj) { | |
| o[prop] = fun(obj[prop]); | |
| } | |
| return o; | |
| }; | |
| let monad = { | |
| plus(val) { | |
| return val + 20; | |
| }, | |
| multiplied(val) { | |
| return val * 2; | |
| } | |
| }; | |
| console.log('plus', loopMap2(test, monad.plus)); | |
| console.log('multiplied', loopMap2(test, monad.multiplied)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment