import { type State } from "https://deno.land/x/hyogwa@v0.1.0-rc.4/src/state.ts";
Effect spec template for state effects.
Examples
Implementing counter
Implementing counter
import { Effect, createCodeConstructor, Effectful } from 'hyogwa/core'
import { State } from 'hyogwa/state'
type Counter = Effect<'Counter', State<number>>
const Counter = createCodeConstructor<Counter>('Counter')
function* increase(count: number): Effectful<Counter, void> {
const prevCount = yield* Counter.get()
yield* Counter.set(prevCount + count)
}
Deriving IO effect from State
Deriving IO effect from State
import { Effect, createCodeConstructor, Effectful } from 'hyogwa/core'
import { State } from 'hyogwa/state'
type IO = Effect<'IO', State<string>>
const IO = createCodeConstructor<IO>('IO')
function* main(): Effectful<IO, void> {
const userName = yield* IO.get()
yield* IO.set(`Hi ${userName}!`)
}