Skip to content

Instantly share code, notes, and snippets.

View hg-pyun's full-sized avatar
🎯
Focusing

Haegul Pyun hg-pyun

🎯
Focusing
View GitHub Profile
@hg-pyun
hg-pyun / currying.12.js
Created September 16, 2018 12:50
currying.12.js
// react
const handleChange = (fieldName) => (event) => {aveField(fieldName, event.target.value)}
<input type="text" onChange={handleChange('email')} ... />
@hg-pyun
hg-pyun / currying.11.js
Created September 16, 2018 12:49
currying.11.js
getters: {
// ...
getTodoById: (state, getters) => (id) => {
return state.todos.find(todo => todo.id === id) }}
store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
@hg-pyun
hg-pyun / currying.10.js
Created September 16, 2018 12:48
currying.10.js
// connect
export default connect()(TodoApp)
// connect with action creators
import * as actionCreators from './actionCreators'
export default connect(null, actionCreators)(TodoApp)
// connect with state
export default connect(state => state)(TodoApp)
@hg-pyun
hg-pyun / currying.09.js
Created September 16, 2018 12:47
currying.09.js
function add(x, y) {
return x+y;
}
let increment = add.bind(undefined, 1);
console.log(increment(4) === 5); // true
@hg-pyun
hg-pyun / currying.08.js
Created September 16, 2018 12:46
currying.08.js
var curry = function(uncurried) {
var parameters = Array.prototype.slice.call(arguments, 1);
return function() {
return uncurried.apply(this, parameters.concat(
Array.prototype.slice.call(arguments, 0)
));
};
};
@hg-pyun
hg-pyun / currying.07.js
Created September 16, 2018 12:45
currying.07.js
let greetDeeplyCurried = greeting => separator => emphasis => name => console.log(greeting + separator + name + emphasis);
let greetAwkwardly = greetDeeplyCurried("Hello")("...")("?");
greetAwkwardly("haegul"); // Hello...haegul?
let sayHello = greetDeeplyCurried("Hello")(", ");
sayHello(".")("haegul"); // Hello, haegul.
let askHello = sayHello("?");
askHello("haegul"); // Hello, haegul?
@hg-pyun
hg-pyun / currying.06.js
Created September 16, 2018 12:42
currying.06.js
// currying
let printInfo = group => name => console.log(group + ', ' + name);
let devGroup = printInfo('developer');
devGroup('haegul'); // developer, haegul
devGroup('jiwon'); // developer, jiwon
devGroup('sungcheon'); // developer, sungcheon
@hg-pyun
hg-pyun / currying.05.js
Created September 16, 2018 12:41
currying.05.js
// print
printInfo('developer', 'haegul'); // developer, haegul
printInfo('developer', 'jiwon'); // developer, jiwon
printInfo('developer', 'sungcheon'); // developer, sungcheon
@hg-pyun
hg-pyun / currying.04.js
Last active September 16, 2018 12:41
currying.04.js
let printInfo = function(group, name){
console.log(group + ', ' + name);
};
printInfo('developer', 'haegul'); // developer, haegul
@hg-pyun
hg-pyun / currying.03.js
Created September 16, 2018 12:38
currying.03.js
let sum = x => y => x+y;
let sum5 = sum(5);
let sum12 = sum5(7);
console.log(sum12, sum(5)(7)); // 12 12