2.1.1 • Published 2 years ago

type-class v2.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 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

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago