Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.14 KB

README.md

File metadata and controls

49 lines (35 loc) · 1.14 KB

affex

GitHub GitHub Workflow Status Codecov npm

Installation

The package is available via npm:

npm install affex

Usage

import { fx } from 'affex'

// Define service interface.
interface Log {
  readonly [fx.uri]?: unique symbol
  (message: string): void
}

// Create service tag.
const tag = fx.tag<Log>()

// Derive effect constructor.
const log = fx.operation(tag)

// Perform effect in generator function.
function* main() {
  yield* log('hello, world')
}

// Create layer with effect handler.
function ConsoleLog() {
  return fx.layer(tag, (message) => console.log(message))
}

// Run program with provided context.
fx.runPromise(main, fx.context().with(ConsoleLog()))

License

MIT