Skip to content

Commit

Permalink
add Result.getOrElse
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed May 29, 2024
1 parent 38fae91 commit a057327
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-actors-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-rx/rx": patch
---

add Result.getOrElse
10 changes: 10 additions & 0 deletions packages/rx/src/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as Cause from "effect/Cause"
import * as Data from "effect/Data"
import * as Exit from "effect/Exit"
import type { LazyArg, LazyArg } from "effect/Function"

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Build

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Build

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Build

Duplicate identifier 'LazyArg'.

Check failure on line 7 in packages/rx/src/Result.ts

View workflow job for this annotation

GitHub Actions / Build

Duplicate identifier 'LazyArg'.
import { dual, identity } from "effect/Function"
import * as Option from "effect/Option"
import { type Pipeable, pipeArguments } from "effect/Pipeable"
Expand Down Expand Up @@ -266,6 +267,15 @@ export const value = <A, E>(self: Result<A, E>): Option.Option<A> => {
return Option.none()
}

/**
* @since 1.0.0
* @category accessors
*/
export const getOrElse: {
<B>(orElse: LazyArg<B>): <A, E>(self: Result<A, E>) => A | B
<A, E, B>(self: Result<A, E>, orElse: LazyArg<B>): A | B
} = dual(2, <A, E, B>(self: Result<A, E>, orElse: LazyArg<B>): A | B => self._tag === "Success" ? self.value : orElse())

/**
* @since 1.0.0
* @category accessors
Expand Down

0 comments on commit a057327

Please sign in to comment.