const casesRx = runtime.rx(() => Effect.gen(function*(){
// ... other defs ...
// no idea if Rx.family is necessary here
const fetchById = Rx.family((caseId: CaseId) =>
Rx.make(client(new ShowCaseRequest({ caseId })))
);
// wrong, but I'm unsure what to do here
const show = <E>(caseId: CaseId): Rx.Rx<Result.Result<Case, E>> =>
Rx.make((get) =>
pipe(
Rx.mapResult(list, (cases) =>
Array.findFirst(cases, (case_) => case_.id === caseId)
),
Rx.map((result) => {
Result.matchWithError(result, {
onInitial: () => Result.initial(),
onSuccess: (result) =>
Option.match(result.value, {
onNone: () => Result.fail(new NoSuchElementException()),
onSome: (case_) => Result.success(case_),
}),
onError: () => get(fetchById(caseId)),
onDefect: () => get(fetchById(caseId)),
});
})
)
);
const casesRx = runtime.rx(() => Effect.gen(function*(){
// ... other defs ...
// no idea if Rx.family is necessary here
const fetchById = Rx.family((caseId: CaseId) =>
Rx.make(client(new ShowCaseRequest({ caseId })))
);
// wrong, but I'm unsure what to do here
const show = <E>(caseId: CaseId): Rx.Rx<Result.Result<Case, E>> =>
Rx.make((get) =>
pipe(
Rx.mapResult(list, (cases) =>
Array.findFirst(cases, (case_) => case_.id === caseId)
),
Rx.map((result) => {
Result.matchWithError(result, {
onInitial: () => Result.initial(),
onSuccess: (result) =>
Option.match(result.value, {
onNone: () => Result.fail(new NoSuchElementException()),
onSome: (case_) => Result.success(case_),
}),
onError: () => get(fetchById(caseId)),
onDefect: () => get(fetchById(caseId)),
});
})
)
);