Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
Created March 17, 2016 19:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangchiqing/863c6a0c7d0c0f41401c to your computer and use it in GitHub Desktop.
Save zhangchiqing/863c6a0c7d0c0f41401c to your computer and use it in GitHub Desktop.
Lazy Lambda
'use strict';
var R = require('ramda');
var expensiveMap = R.compose(R.join(''), R.repeat(R.__, 10000));
var data = R.range(1, 10000);
// $ time node lazy.js
// node lazy.js 3.42s user 0.16s system 99% cpu 3.584 total
R.take(1, R.map(expensiveMap, data));
// $ time node lazy.js
// node sdfsdf.js 0.10s user 0.01s system 94% cpu 0.119 total
R.into([], R.compose(R.take(1), R.map(expensiveMap)), data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment