Created
March 17, 2016 19:43
-
-
Save zhangchiqing/863c6a0c7d0c0f41401c to your computer and use it in GitHub Desktop.
Lazy Lambda
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
'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