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

Add arrow function based implementation #8

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
22 changes: 22 additions & 0 deletions pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ function values (ary) {
}
}

/*
Or equivalently in the arrow function style:

const values = ary => {
let i = 0
return (abort, cb) => (i < ary.length)
? cb(null, ary[i])
: cb(true)
}
*/

// Usage example
const show = console.log
, str = values([1,2,3])

show("Pulling data from the stream...")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rename console.log? I can expect the reader to already know what console.log does, so they can understand each line, but now I had to go figure out what show was. At first I thought it was a module.

str(null, show)
str(null, show)
str(null, show)
str(null, show)

/*

pull-streams don't really have a writable stream per se. "writable" implys that
Expand Down Expand Up @@ -152,6 +173,7 @@ now we can pipe the infinite stream through this,
and it will stop after 101 items!
*/

show("Pulling from the infinite stream...")
pull(infinite(), mapper, take(101), sink)

/*
Expand Down