Created
January 10, 2017 14:34
-
-
Save fmsf/acb25c66a26955358b330f7d55bc3cc2 to your computer and use it in GitHub Desktop.
This file contains 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
// @fmsf303 <-- will send the gist later | |
// Cool stuff: | |
// Youtube: -> The Role of a Forward Deployed Software Engineer | |
// function sum(a, b) { | |
// return a + b; | |
// } | |
const sum = (a, b) => a + b; | |
const not = (v) => !v; | |
const isEven = (num) => num % 2 == 0; | |
// console.log(sum(2,3)); | |
// const double = (num) => num * 2; | |
// const double = (num) => sum(num, num); | |
const twice = (fn) => (num) => fn(num, num); | |
const double = twice(sum); | |
console.log(twice(sum)(3)); | |
console.log(double(7)); | |
// const isOdd = (num) => num % 2 != 0; | |
// const isOdd = (num) => !isEven(num); | |
// const isOdd = (num) => not(isEven(num)); | |
const chain = (fn1) => (fn2) => (value) => fn1(fn2(value)); | |
const isOdd = chain(not)(isEven); | |
console.log(" --> " + isOdd(7)); | |
// chain(not)(isEven)(8); | |
// data --> { | |
// firstName: "maria", | |
// lastName: "silva" | |
// } | |
//$.get("/getUser/" + username, | |
// (data) => setPageTitle(data.firstName + " " + lastName)); | |
// userOperations.js | |
const getFullName = (user) => user.firstName + " " + user.lastName; | |
// $.get("/getUser/" + username, (data) => setPageTitle(getFullName(data))); | |
// $.get("/getUser/" + username, chain(setPageTitle)(getFullName)); | |
// currying | |
const sum2 = (a) => (b) => a + b; | |
console.log(sum2(7)(5)); | |
let indexes = [1,2,3]; // [1001, 1002, 1003] | |
// 1000 | |
const add1000 = sum2(1000); | |
console.log(indexes.map(sum2(1000))); | |
// if( user.name!=null && user.name.length!=0 && (user.address == null && ( is... ); | |
boolean isUserValid(user) => name!=null && name.length!=0 && (user.address == null && ( is... ); | |
... | |
if(userIsValid(user)) | |
... | |
const userArray = [allusers...]; | |
userArray.filter(userIsValid) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usually twice is to apply the function twice
classically it should be:
const twice = fn => num => fn(fn(num));
then use partial application to get the sum2(3) -> add3 and then twice that... probably.