Accessing Intermediate Values in Effect Pipelines Without Breaking Functional Paradigms

Intuitively this isn't a good idea because it breaks the functional aspect but I'm not sure what the alternative is. How can I get the value from getAIResponseContent in the catchTag, essentially skipping over one pipe ?

const parseAIJSONResponseContent = (content: AIResponseSchema) => {
    let original = ''
    return pipe(
        getAIResponseContent(content),
        Effect.tap((str) => (original = str)), // store value???
        Effect.flatMap(extractJSONstring),
        Effect.catchTag('NoSuchElementException', err => new Error("UnJSONableAIResponse: " + original)), // use value ??
        Effect.flatMap(safeJSONParse)
    )
}
Was this page helpful?