0.4.1 • Published 29 days ago

liminal v0.4.1

Weekly downloads
14
License
ISC
Repository
-
Last release
29 days ago

Liminal - functional tools for composing applications

Notes

Projects is in a POC stage. Stay tuned!

API

Functional composition

pipe

Executes functions in provided order, starting with initial value.

import { pipe } from 'liminal'

const doubleSquare = pipe(
  (x) => x * 2,
  (x) => x ** 2,
)

const result = doubleSquare(2) // -> 16

compose

Executes functions in reversed order, starting with initial value.

import { compose } from 'liminal'

const doubleSquare = compose(
  (x) => x ** 2,
  (x) => x * 2,
)

const result = doubleSquare(2) // -> 16

railSync

Works similar to pipe, but additionally catches errors and pipes them downstream as a value.

Errors can be thrown or returned.

import { compose } from 'liminal'

const doubleSquare = compose(
  (x) => x ** 2,
  (x) => x * 2,
)

const result = doubleSquare(2) // -> 16
import { compose } from 'liminal'

const doubleSquare = compose(
  (x) => {
    if (typeof x !== 'number') {
      return new Error('Number expected')
    }

    return x ** 2
  },
  (x) => x * 2,
)

const result = doubleSquare('foo') // -> Error object

rail

Works similar to rail, but additionally waits for promises if are returned and passes result values between functions.

Errors can be thrown or returned.

import { compose } from 'liminal'

const doubleSquare = compose(
  (x) => x ** 2,
  (x) => x * 2,
)

const main = async () => {
  const result = await doubleSquare(Promise.resolve(2)) // -> 16
}

main()
0.4.1

29 days ago

0.4.0

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago