Skip to content

embedded-insurance/effect-use

Repository files navigation


💁

effect-use

effect-use is a library that collects common Effect wrappers in one place for developer convenience.

Project Status

Alpha software, subject to change.

Packages

Usage

import { GitHub } from '@effect-use/github'
import { Effect, Layer, pipe } from 'effect'

const getLatestCommit = pipe(
  Effect.flatMap(GitHub, github => github.getRepo({owner: 'embedded-insurance', repo: 'effect-use'})),
  Effect.map(result => result.repo.latestCommit),
  Effect.mapError(e => ({ _tag: "Whoops" }))
)

// Let's provide our dependencies
// And instead of the real GitHub, let's just make something up that looks exactly like it.
// a.k.a., "it satisfies the interface"
const GitHubLayerTest = Layer.succeed(GitHub, {
  getRepo: (args: any)=> ({ latestCommit: '125' })
} as GitHub)

const result = pipe(
  getLatestCommit,
  Effect.provide(GitHubLayerTest),
  Effect.runPromise
)

expect(result).toEqual({latestCommit: '125'})