Effect CommunityEC
Effect Community3y ago
19 replies
canastro

Using effect.match for running side-effects

Is it possible to use effect.match to run side-effects?

I would like to be able to do something like this:

Effect.tap((events) =>
    Effect.sync(() =>
        pipe(
            events,
            ReadonlyArray.forEach(
                pipe(
                    Match.type<InterviewSessionEvent>(),
                    Match.tag('ParticipantReplySent', (event) =>
                        Effect.sync(() => addMessage(event.data.message))
                    ),
                    Match.tag('AgentReplied', (event) =>
                        Effect.sync(() => addMessage(event.data.message))
                    ),
                    Match.orElse(() => Effect.unit)
                )
            )
        )
    )
),
Was this page helpful?