Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated unfold and range methods for significant performance improvement (see notes) #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,13 @@ const para = (f, acc, xs) =>

```js
const unfold = (f, seed) => {
const go = (f, seed, acc) => {
const res = f(seed);
return res ? go(f, res[1], acc.concat([res[0]])) : acc;
const next = (f, val, acc) => {
if (!f(val)) return acc
const resVal = f(val);
acc.push(resVal[0])
return next(f, resVal[1], acc);
}
return go(f, seed, [])
return next(f, seed, [])
}
unfold(x =>
x < 26
Expand All @@ -304,11 +306,11 @@ unfold(x =>
### Range

```js
const range = (i, count) =>
unfold(x => (x <= count)
? [x, x+1]
const range = (start, end) =>
unfold(val => (val <= end)
? [val, val + 1]
: null
, i);
, start);
range(5, 10)
//=> [ 5, 6, 7, 8, 9, 10 ]
```
Expand Down