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

pipeline.sjs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pipeline.sjs

Naturally expressive functional composition

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Pipeline.sjs

Pipeline

Version: 1.0.2
Master build: Master branch build status

This library provides pipelining syntax to achieve naturally expressive functional composition with a little help from Sweet.js. It can be installed in whichever way you prefer, but I recommend NPM.

The motivation was to make reading functional composition more natural by writing left to right rather than inside out. My original choice of operator was |> to match a similar operator in Elixir, but due to some limitations of Sweet.js this wasn't possible. The examples below show usage with the default >> operator.

Usage examples

var foo = function(){},
    bar = function(){},
    baz = function(){};

// Basic composition
123 >> foo; // Compiles to foo(123);

// Functional composition
foo >> bar; // Compiles to bar(foo);

// Chained composition
123 >> foo >> bar; // Compiles to bar(foo(123));

// Multi-line composition
123
>> foo
>> bar
>> baz; // Compiles to baz(bar(foo(123)));

// Partially applied composition
foo >> bar >> baz(123); // Compiles to baz(123, bar(foo));

// Partially applied with many arguments
foo >> bar(1, 2, 3) >> baz; // Compiles to baz(bar(1, 2, 3, foo));

Transpiling

Whenever you use this or any other Sweet.js macro, you need to run it through sjs.

$ npm install pipeline.sjs sweet.js
$ node_modules/.bin/sjs -m pipeline.sjs/macro mysweetfile.sjs

Custom operator

You can change the operator used in this macro by running the build script with your new operator.

$ MACRO_OP='>>' npm run build

Contributing

I accept contributions to the source via Pull Request, but passing unit tests must be included before it will be considered for merge.

$ npm run build
$ npm test

If you have Vagrant installed, you can build the dev environment to assist development. The repository will be mounted in /srv.

$ curl -O https://raw.github.com/adlawson/vagrantfiles/master/nodejs/Vagrantfile
$ vagrant up
$ vagrant ssh

Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)
$ cd /srv

License

The content of this library is released under the MIT License by Andrew Lawson.
You can find a copy of this license in LICENSE or at http://www.opensource.org/licenses/mit.

Keywords

FAQs

Package last updated on 31 Mar 2014

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