0.12.0 • Published 1 year ago
@inato/effect-fpts-interop v0.12.0
@inato/effect-fpts-interop
Helper functions to interoperate between the Effect type and the ReaderTaskEither type.
!NOTE This repository acts as supporting document for this article that describe how at Inato we successfully migrated to Effect.
Installation
You can install this package via pnpm:
pnpm install @inato/effect-fpts-interop
Usage
portToEffect
import {
getFptsMapping,
portToEffect,
type FptsAccess,
type FptsConvertible,
} from "@inato/effect-fpts-interop";
interface MeasureString extends FptsConvertible<"measureString"> {
measure: (value: string) => ReaderTaskEither<unknown, Error, number>
}
interface MeasureStringAccess extends FptsAccess<MeasureString> { }
declare const MeasureStringFpts: {
measure: (value: string) => ReaderTaskEither<MeasureString, Error, number>
}
const Tag = Context.GenericTag<MeasureString>("MeasureString")
const MeasureString = portToEffect(
MeasureStringFpts,
getFptsMapping(Tag, "measureString")
)
MeasureString.measure("hello 👋") // Effect<number, Error, MeasureString>
portToFpts
import {
getFptsMapping,
portToFpts,
type FptsAccess,
type FptsConvertible,
} from "@inato/effect-fpts-interop";
interface MeasureString extends FptsConvertible<"measureString"> {
measure: (value: string) => Effect<number, Error>
}
interface MeasureStringAccess extends FptsAccess<MeasureString> { }
declare const MeasureStringFpts: {
measure: (value: string) => ReaderTaskEither<MeasureString, Error, number>
}
const Tag = Context.GenericTag<MeasureString>("MeasureString")
const MeasureString = Effect.serviceFunctions(Tag)
const MeasureStringFpts = portToFpts(
MeasureString,
getFptsMapping(Tag, "measureString")
)
MeasureStringFpts.measure("hello 👋") // ReaderTaskEither<MeasureStringAccess, Error, number>
And more.. Have a look at the example section!