effect icon indicating copy to clipboard operation
effect copied to clipboard

Effect.retry no longer infer error

Open mikearnaldi opened this issue 3 years ago • 1 comments

When removing lazy from Effect.retry we lost inference of E, make sure arguments where inference should be deferred to be lazy.

export const getTodo = (id: number) =>
  pipe(
    Http.request(`https://jsonplaceholder.typicode.com/todos/${id}`),
    Effect.flatMap(Http.jsonBody),
    Effect.retry(
      pipe(
        Http.defaultRetrySchedule,
        Schedule.whileInput((error: Http.FetchError | Http.JsonBodyError) => error._tag !== "JsonBodyError")
      )
    )
  );

vs

export const getTodo = (id: number) =>
  pipe(
    Http.request(`https://jsonplaceholder.typicode.com/todos/${id}`),
    Effect.flatMap(Http.jsonBody),
    Effect.retry(() =>
      pipe(
        Http.defaultRetrySchedule,
        Schedule.whileInput((error) => error._tag !== "JsonBodyError")
      )
    )
  );

mikearnaldi avatar Sep 30 '22 09:09 mikearnaldi

Also check why the schedule input doesn't appear to be contravariant, i.e. if E = HttpError | JsonError and Schedule accepts { _tag: string } it should work

mikearnaldi avatar Sep 30 '22 10:09 mikearnaldi

I wonder if allowing a lazy schedule is a good option still?

tim-smart avatar Mar 19 '24 04:03 tim-smart

I think it's fine as we have it imho

mikearnaldi avatar Mar 25 '24 11:03 mikearnaldi