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

threading

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

threading

A clojure-inspired utility for threading arbitrary data into the first or last argument of a sequence of functions

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
20
decreased by-37.5%
Maintainers
1
Weekly downloads
 
Created
Source

threading

A clojure-inspired utility for threading arbitrary data into the first or last argument of a sequence of functions

Motivation

In order to compose function operations on arbitrary data, you have to nest functions

expect(subtract(add(3, 3) 3)).toBe(3);

The legibility of the example decreases as the number of functions increase.

Example Usage

Thread-first

Apply the initial & resulting values of the function list to the first argument of the function.

Simply provide an initial value then the functions you'd like to compose on the value.

import { threadFirst } from 'threading';

const value = threadFirst(
    5,
    timesThree,
    plusOne
);

expect(value).toBe(16);

To use with a function that should already have a value you can pass an array containing the function and the other arguments.

import { threadFirst } from 'threading';

const value = threadFirst(
  5,
  [times 3],
  [divideby 5]
);

expect(value).toBe(3);
Thread-last

Apply the initial & resulting values of the function list to the last argument of the function.

Simply provide an initial value then the functions you'd like to compose on the value.

import { threadLast } from 'threading';

const value = threadLast(
    5,
    timesThree,
    plusOne
);

expect(value).toBe(16);

To use with a function that should already have a value you can pass an array containing the function and the other arguments.

import { threadLast } from 'threading';

const value = threadFirst(
  5,
  [times 2],
  [divideby 5]
);

expect(value).toBe(0.5);

Keywords

FAQs

Package last updated on 03 Dec 2015

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