Socket
Socket
Sign inDemoInstall

clojure-thread-async

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    clojure-thread-async

Clojure thread macro in JS


Version published
Weekly downloads
2
Maintainers
1
Install size
5.05 kB
Created
Weekly downloads
 

Readme

Source

clojure-thread-js-async

Clojure threading macro. Supports first, last, and as macro. No support for binding.

Usage

const thread = require('clojure-thread-async')

// first
// returns 9
await thread.first(
  1,
  x => x * 10,
  [(x, y) => x - y, 1]
)

// last
// returns -9
await thread.last(
  1,
  x => x * 10,
  [(x, y) => x - y, 1]
)

// as
// returns -8
// second argument must be a function that
// takes a placeholder as input (which is just
// an empty object) and
// returns an array of functions or arrays
await thread.as(
  1,
  placeholder => [
    x => x * 10,
    [(x, y) => x - y, placeholder, 1],
    [(x, y) => x - y, 1, placeholder]
  ]
)

// React Redux reducer
const reducer = (state = 0, action) => {
  switch(action.type) {
    case "INC":
      return state + 1
    default:
      return state
  }
}

const state = thread.first(
  reducer(undefined, {}),
  [reducer, {type: "INC"}],
)

console.log(state == 1)

Keywords

FAQs

Last updated on 28 Dec 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc