Code Monkey home page Code Monkey logo

deno-compose's Introduction

Overload Definition of Pipe and Compose

pipe, pipeline, and compose functions with 64 overloads per function.

What's the point?

This package not only provides simple pipe, pipeline, and compose implementation, it also provides 64 TypeScript overloads for each function. [See index.d.ts]

Usage

Import as module

URLs to import from: (replace :VERSION with suitable version, which are git tags)

  • GitHub User Content: https://raw.githubusercontent.com/KSXGitHub/deno-compose/:VERSION/index.js
  • GitHub Pages: https://ksxgithub.github.io/deno-compose/index.js (always master branch)
  • Deno Third-Party Modules: https://deno.land/x/compose@:VERSION/index.js

Code Example:

import {
  pipe,
  pipeline,
  compose,
  pipeUnary,
  pipelineUnary,
  composeUnary,
} from 'https://deno.land/x/[email protected]/index.js'

APIs

pipe

Signature: pipe (value, ...functions) → result

const y = pipe(x0, f1, f2, f3)

is equivalent to

const x1 = f1(x0)
const x2 = f2(x1)
const y = f3(x2)

or

const y = f3(f2(f1(x0)))

pipeline

Signature: pipeline (...functions) → function

const fn = pipeline(f0, f1, f2, f3)

is equivalent to

const fn = (...args) => f3(f2(f1(f0(...args))))

compose

Signature: compose (...functions) → function

const fn = compose(f3, f2, f1, f0)

is equivalent to

const fn = (...args) => f3(f2(f1(f0(...args))))

pipelineUnary

Signature: pipeline (...functions) → function

const fn = pipe(f0, f1, f2, f3)

is equivalent to

const fn = x => f3(f2(f1(f0(x))))

composeUnary

Signature: compose (...functions) → function

const fn = compose(f3, f2, f1, f0)

is equivalent to

const fn = x => f3(f2(f1(f0(x))))

composeRight

It is just an alias of pipeline

composeUnaryRight

It is just an alias of pipelineUnary

Example

// pipe
const y0 = pipe(x, f1, f2, f3, f4)

// pipeline
const g1 = pipeline(f0, f1, f2, f3, f4)
const y1 = g1(...args)

// compose
const g2 = compose(f4, f3, f2, f1, f0)
const y2 = g2(...args)

Development

Code Style

This project is formatted according to sane-fmt.

License

MIT © Hoàng Văn Khải

deno-compose's People

Contributors

ksxgithub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

deno-compose's Issues

Typo in readme

A small mistake:

const y = pipe(x0, f1, f2, f3)

is equivalent to

const x1 = f1(x0)
const x2 = f2(x1)
const y = f3(x2)

instead of

const x1 = f1(x0)
const x2 = f2(x1)
const x3 = f3(x2)
const y = f3(x3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.