Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@craftgear
Last active October 6, 2018 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craftgear/bcf433f72c170c579fb8a1ad2f6c52f8 to your computer and use it in GitHub Desktop.
Save craftgear/bcf433f72c170c579fb8a1ad2f6c52f8 to your computer and use it in GitHub Desktop.
#SurviveJS 05 LT「forループを越えて」
const double = x => x * 2;
const over5 = x => x > 5;
const a = [1, 2, 3].map(double).filter(over5);
console.log('********* a', a);
import * as R from 'ramda';
const times2Over5 = R.compose(
R.tap(console.log),
R.filter(over5),
R.tap(console.log),
R.map(double)
);
const b = times2Over5([1, 2, 3]);
console.log('********* b', b);
const c = times2Over5({ a: 1, b: 2, c: 3, str: 'string' });
console.log('********* c', c);
// error!
// const hoge = { a: 1, b: 2, c: 3 };
// hoge.map(x => x);
// error!
// const e = times2Over5(null);
// console.log('********* e', e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment