Skip to content

a simpler way to create a continuation function with initial arguments and then be called with the remaining arguments

License

Notifications You must be signed in to change notification settings

joaquimserafim/apply

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apply

a simpler way to create a continuation function with initial arguments and then be called with the remaining arguments


Build StatusCode Coverage 100%ISC LicenseNodeJS

JavaScript Style Guide

api

apply(function_to_apply, [initial_arguments])

examples

first example

const apply = require('node-apply')

const foo = apply(puts, 'one')

foo('two', 'three')// will return `one two three`

function puts (one, two, three) {
  return `${one} ${two} ${three}`
}

second example

const apply = require('node-apply')
const async = require('lasync')

async.waterfall(
  [
    apply(putsAsync, 'one'),
    apply(putsAsync, 'two'),
    apply(putsAsync, 'three')
  ],
  (err, res) => {
    // res will be 'one - two - three'
  }
)

function putsAsync (...args) {
  let cb = args.pop()
  cb(null, args.reverse().join(' - '))
}

PS: with NodeJS 7 should use the bind function instead

ISC License (ISC)

About

a simpler way to create a continuation function with initial arguments and then be called with the remaining arguments

Resources

License

Stars

Watchers

Forks

Packages

No packages published