type-class
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

Eitherly

Overview

Helpful type classes for TypeScript This package was formerly named 'type-class'

Install

npm install type-class
import { AsyncResult, tryAsyncResult } from "../src/index";

const goodQuestion = 'The Answer to the Ultimate Question of Life, the Universe, and Everything?'
const badQuestion = 'What is that?'

async function impureAnswer(question: string): Promise<number> {
  if(question === goodQuestion)
    return 42
  throw 'Wrong question'
}

function pureAnswer(question: string): AsyncResult<number> {
  return tryAsyncResult(() => impureAnswer(question))
}

pureAnswer(goodQuestion)
  .map(console.log) // 42
  .mapL(console.error)
  .run()
pureAnswer(badQuestion)
  .map(console.log)
  .mapL(console.error) // Wrong question
  .run()

Examples

Dummy Application using only AsyncResult (i.e. AsyncEither) example

Either example

AsyncEither example

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i type-class

    Weekly Downloads

    1

    Version

    2.1.1

    License

    ISC

    Unpacked Size

    18.2 kB

    Total Files

    16

    Last publish

    Collaborators

    • tariqqubti