Skip to content

Commit

Permalink
Prevent Effect.if from crashing when first argument is not an Effect (#…
Browse files Browse the repository at this point in the history
…2299)

Co-authored-by: Tim <hello@timsmart.co>
Co-authored-by: Michael Arnaldi <michael.arnaldi@effectful.co>
  • Loading branch information
3 people authored Mar 16, 2024
1 parent 6b20bad commit 814e5b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wicked-apples-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Prevent Effect.if from crashing when first argument is not an Effect
3 changes: 2 additions & 1 deletion packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@ export const if_ = dual<
(self: boolean | Effect.Effect<unknown, unknown, unknown>, { onFalse, onTrue }: {
readonly onTrue: Effect.Effect<unknown, unknown, unknown>
readonly onFalse: Effect.Effect<unknown, unknown, unknown>
}) => typeof self === "boolean" ? (self ? onTrue : onFalse) : flatMap(self, (b) => (b ? onTrue : onFalse))
// eslint-disable-next-line no-extra-boolean-cast
}) => isEffect(self) ? flatMap(self, (b) => (b ? onTrue : onFalse)) : Boolean(self) ? onTrue : onFalse
)

/* @internal */
Expand Down

0 comments on commit 814e5b8

Please # to comment.