Exploring Backend Development with Effects: A Guide to Arguments Passing

👋 hey! i am trying to test the waters by writing a part of our backend using effects.

i have found the docs describing how to

- call non-effect code (https://effect.website/docs/guides/essentials/creating-effects#cheatsheet), and how to
- run effects (https://effect.website/docs/guides/essentials/running-effects#runsync)

but it's quite unclear how to pass in arguments to the effects. from the conversations above my guess is that it's

const program = ({ root }: { root: PathUtils.PosixPath; namespace: string }) =>
  Effect.gen(function* ($) {
    const a = yield* $(Effect.succeed(root))

    return a
  })


but i am very uncertain... is this the way to go?

in case it helps: my impression after reading the docs for 30' was that i can either do a console.log hello world app or check react demo.

I remember when Elm-Lang came out many teams tried rewriting only a single component in Elm and hooked it up with the rest of the codebase. I am trying to do the same with EffecTS, but I am struggling with the docs.

i remember David's XState slides at the Effect Days that had no real integration and were just calling Effect runtime for every change, but that made all the difference for me. i've found https://github.com/Effect-TS/examples/blob/main/node-scripts/src/fs-write-file.ts, but these showcase standalone programs, not so much parts of the code rewriten in EffecTS.

it would've help me plenty if there was a page next to the quickstart that showcased how I can use effects in a subpart of my existing js codenase (e.g. a function that looks to the outside as if you wrote it without effects but uses them internally).

// Example
import { Effect } from 'effect'

const program = (params) => Effect.gen(function* {})

// experiments ...

export function doX(params) {
  return Effect.runSync(program(params))
}
Was this page helpful?