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

part

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

part

This micro library encourages functional programming by making native methods available as partially applied functions.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
increased by285.71%
Maintainers
1
Weekly downloads
 
Created
Source

_part_

This micro library encourages functional programming by making native methods available as partially applied functions.

//typical receiver-method-arguments pattern
[1,2,3].map( function (n) { return n + 1; } ); // [2,3,4]

The "left-part" functions prepend the method name with an underscore and expect the receiver as the first argument in the first invocation.

_map( [1,2,3] )( function (n) { return n + 1; } ); // [2,3,4]

The "right-part" functions suffix the method name with an underscore and expect the receiver as the first argument in the function returned by the first invocation.

map_( function (n) { return n + 1; } )( [1,2,3] ); // [2,3,4]

See the docs.

Try the live demo.

Getting Started

See the following examples of how to include _part_.

Custom namespace;

// NodeJS example
var _part_ = require( "part" );
var util = {};
_part_._borrow( util )( Array.prototype, "reduce" );
function add( a, b ) { return +a + +b; }
util.sum = util.reduce_( add );
module.exports = util;
<!-- Browser example -->
<script src="build/src/part.min.js">
<script>
(function (global, util) {
  function add( a, b ) { return +a + +b; }
  _part_._borrow( util )( Array.prototype, "reduce" );
  util.sum = util.reduce_( add );
  global.util = util;
}(this, {}));
</script>

Extending the _part_ namespace;

// NodeJS example
var _part_ = require( "part" );
_part_._borrow( util )( Array.prototype, "reduce" );
function add( a, b ) { return +a + +b; }
var sum = util.reduce_( add );
<!-- Browser example -->
<script src="build/src/part.min.js">
<script>
function add( a, b ) { return +a + +b; }
_part_.borrow( Array.prototype, "reduce" );
var sum = _part_.reduce_( add );
</script>

Non-namespaced utilities

// NodeJS example
var _part_ = require("part");
var reduce_ = _part_.create_(Array.prototype.reduce);
function add( a, b ) { return +a + +b; }
var sum = reduce_( add );
<!-- Browser example -->
<script src="build/src/part.min.js">
<script>
function add( a, b ) { return +a + +b; }
_part_._borrow( this )( Array.prototype, "reduce" );
var sum = reduce_( add );
</script>

Updates

  • 2013-12-11 - Added papply to the _part_ namespace.

Keywords

FAQs

Package last updated on 16 Jan 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