2.1.1 • Published 3 years ago

type-class v2.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago