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
'} |
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
//OOP | |
class Parent { | |
constructor(name, job) { | |
this.name = name; | |
this.job = job; | |
} | |
} | |
const solo = new Parent('Han', 'smuggler'); // {name: 'Han', job: 'smuggler'} |
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
//OOP | |
class Parent { | |
constructor(name, job) { | |
this.name = name; | |
this.job = job; | |
} | |
} | |
const solo = new Parent('Han', 'smuggler'); // {name: 'Han', job: 'smuggler'} |
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
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop}); | |
const curry = (func, arg) => { | |
return (...args) => func(arg, ...args); | |
}; | |
const giveName = curry(giveProp, 'name'); | |
const giveJob = curry(giveProp, 'job'); | |
const giveHero = curry(giveProp, 'hero'); |
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
// pure | |
const addOne = num => num + 1; | |
//impure: modifies input variable | |
const addOneImpure = num => num++; | |
//pure | |
const addOneToAll = arr => arr.map(addOne); | |
//impure: modifies input array |
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
//Ramda | |
const R = require('ramda'); | |
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop}); | |
const givePropCurry = R.curry(giveProp); | |
const giveName = givePropCurry('name'); | |
const giveJob = givePropCurry(giveProp, 'job'); | |
const giveHero = givePropCurry('hero'); |
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
//Ramda | |
const R = require('ramda'); | |
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop}); | |
const givePropCurry = R.curry(giveProp); | |
const giveName = givePropCurry('name'); | |
const giveJob = givePropCurry('job'); | |
const giveHero = givePropCurry('hero'); |
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
//Ramda | |
const R = require('ramda'); | |
//this is the same as | |
const makeRen = obj => giveHero( | |
'Darth Vader', | |
giveName('Kylo', obj) | |
); | |
// this |
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
const R = require('ramda'); | |
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop}); | |
const givePropCurry = R.curry(giveProp); | |
const giveName = givePropCurry('name'); | |
const giveJob = givePropCurry('job'); | |
const giveHero = givePropCurry('hero'); |
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
//Ramda | |
const R = require('ramda'); | |
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop}); | |
const givePropCurry = R.curry(giveProp); | |
const giveName = givePropCurry('name'); | |
const giveJob = givePropCurry('job'); | |
const giveHero = givePropCurry('hero'); | |
const giveJobSmuggler = giveJob('smuggler') |