Skip to content

Instantly share code, notes, and snippets.

@zspecza
Created November 16, 2016 21:26
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 zspecza/169a51e0dbfafe6bcb7b4fa5906f350c to your computer and use it in GitHub Desktop.
Save zspecza/169a51e0dbfafe6bcb7b4fa5906f350c to your computer and use it in GitHub Desktop.
const users = {
1: { name: 'bob' },
2: { name: 'sally' }
}
const posts = [
{ author: 'sally', title: 'Hello World' },
{ author: 'bob', title: 'How to do stuff' }
]
const getUserName = sequentialCallback(
(id, callback) => callback(null, users[id]),
(user, callback) => callback(null, user.name)
)
const getUserPosts = sequentialCallback(
getUserName,
(name, callback) => callback(null, posts.filter((p) => p.author === name))
)
getUserPosts(2, (err, posts) => {
console.log(posts)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment