// ets_tracing: off import * as T from "../effect.js" export type Decision = Done | Continue export type Interval = number export type StepFunction = ( interval: Interval, inp: Inp ) => T.Effect> export class Done { readonly _tag = "Done" constructor(readonly out: Out) {} } export class Continue { readonly _tag = "Continue" constructor( readonly out: Out, readonly interval: Interval, readonly next: StepFunction ) {} } export function makeDone(o: Out): Decision { return new Done(o) } export function makeContinue( out: Out, interval: Interval, next: StepFunction ): Decision { return new Continue(out, interval, next) } export function toDone(self: Decision): Done { switch (self._tag) { case "Done": { return self } case "Continue": { return new Done(self.out) } } } export function map(f: (o: Out) => Out1) { return (self: Decision): Decision => { switch (self._tag) { case "Done": { return new Done(f(self.out)) } case "Continue": { return new Continue(f(self.out), self.interval, (n, i) => T.map_(self.next(n, i), map(f)) ) } } } } export function contramap(f: (i: Inp1) => Inp) { return (self: Decision): Decision => { switch (self._tag) { case "Done": { return self } case "Continue": { return new Continue(self.out, self.interval, (n, i) => T.map_(self.next(n, f(i)), contramap(f)) ) } } } } export function as(o: Out1) { return (self: Decision): Decision => map(() => o)(self) } export function done(a: A): StepFunction { return () => T.succeed(new Done(a)) }