0.4.1 • Published 29 days ago
liminal v0.4.1
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()