Socket
Book a DemoInstallSign in
Socket

clojure-thread

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clojure-thread

Clojure thread macro in JS

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

clojure-thread-js

Clojure threading macro. Supports first, last, and as macro. No support for binding. Might be useful for testing React / Redux reducer.

Usage

const thread = require('clojure-thread')

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

// last
// returns -9
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
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)

License

MIT

Keywords

Clojure

FAQs

Package last updated on 18 Dec 2017

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