JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q19339F
  • License MIT

Railway-oriented programming helper library

Package Exports

  • baccano

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (baccano) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Baccano

A railway-oriented programming helper library.

forthebadge forthebadge forthebadge

Getting Started

Importing the library

To use the library, first import it:

In Node:

const { compose } = require('baccano')

As ES Module:

import { compose } from 'baccano'

On the browser:

<script src="https://cdn.jsdelivr.net/npm/baccano/baccano.min.js"></script>
<script>
    const { compose } = Baccano
</script>

Using the library

// Define Errors
import { Success, SomeError, compose, fromUnary } from 'baccano'

const DIVISON_BY_ZERO = Symbol.for('DIVISION_BY_ZERO')

const divideBy = n => x => {
  if (n === 0) {
    return SomeError(DIVISON_BY_ZERO, "Cannot divide by zero.")
  } else {
    return Success(n / x)
  }
}

const plusOne = x => {
  return Success(x + 1)
}

(async () => {
  const compatibleDivideBy = fromUnary(divideBy(0))
  const compatiblePlusOne = fromUnary(plusOne)
  const pipeline = compose(compatiblePlusOne, compatibleDivideBy, compatiblePlusOne)
  const result = await pipeline(2)

  console.log(result.value)
  console.log(result.errors)
})()

Notes

  • I named the library Baccano because when I thought about trains and railways, I thought of the Baccano anime. @egoist is not the only one fond of anime references LOL.

License

MIT