Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/hyogwa/src/state.ts>State

Natural 🌿 effect system that fits TypeScript
Latest
interface State
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

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

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}!`)
}

Methods

get(): T
set(nextState: T): void