Effect CommunityEC
Effect Community11mo ago
6 replies
Chris

Creating a curried function that involves passing a service to a function and then constructing a...

I'm not sure it what I want is possible but I'm trying to pass in a Service to a curried function and then construct a layer for it, and the types just won't work, what is the way to type something which allows:
const makeX = <T, A, R extends Context.Tag<any, T>>(r: R) => <E>(eff: Effect.Effect<A, E, R | SomeOther>) => (event: T, other: String) => eff.pipe(
  Effect.provide(SomeOther, other),
  Effect.provide(r, event),
  Effect.runPromise
)
// usage:
class Event extends Context.Tag('@foobar/some-event')<
    Event,
    number
>() {}
const x = makeX(Event)
const handler = Event.pipe(Effect.flatMap(Effect.logInfo))
handler(2, 'foobar') // should log out 2


Is it possible to achieve something like this?
Was this page helpful?