Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

andthen

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

andthen

Async function composition with parameter fixing abiliy.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

andthen

Async function composition with parameter fixing abiliy.

$ npm install andthen

See Also: comp

Usage

Functions almost same as other function composition libraries, except that it lets you bind a property of a produced value to following function.

Simplest usage could look like:


andThen = require('andThen')

andThen(getContents, 'posts', getPosts, 'images', getImages)(function(error, contents){

    contents.posts
    // => ['Foo', 'bar', 'qux']

    contents.images
    // => ['11.jpg', '7.jpg', '3.jpg']

})

function getContents(callback){
    callback(undefined, { posts: [3, 1, 4], images: [11, 7, 3])
}

function getPosts(ids, callback){
    callback(undefined, ['Foo', 'bar', 'qux'])
}

function getImages(ids, callback){
    callback(undefined, ['11.jpg', '7.jpg', '3.jpg'])
}

More detailed example with full functional programming armory:


andThen   = require('andThen')
map       = require('map')
partial   = require('new-partial')

getPosts  = partial(map, getPost)
getPhotos = partial(map, getPhoto)

getProfile = andThen(getUser, 'posts', getPosts, 'photos', getPhotos)

getProfile(1, function(error, profile){

    profile.posts[0].title, profile.posts[2].content
    // => Post #1, Content #5

    profile.photos[0].path, profile.photos[1].path
    // => /photos/2.jpg, /photos/7.jpg

})

function getUser(id, callback){

  callback(undefined, {
      name   : 'Smith',
      posts  : [1, 3, 5],
      photos : [2, 7, 11]
  })

}

function getPost(id, callback){

    callback(undefined, {
        title: 'Post #' + id,
        content: 'Content #' + id
    })

}

function getPhoto(id, callback){

    callback(undefined, {
        path: '/photos' + id + '.jpg
    })

}

FAQs

Package last updated on 03 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc