Skip to content

Commit

Permalink
fn: breaking - make or else functions accept error argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ProofOfKeags committed Nov 7, 2024
1 parent dd7f156 commit 9f35664
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fn/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ func (r Result[T]) UnwrapOr(defaultValue T) T {

// UnwrapOrElse returns the success value or computes a value from a function
// if it's an error.
func (r Result[T]) UnwrapOrElse(f func() T) T {
func (r Result[T]) UnwrapOrElse(f func(error) T) T {
if r.IsErr() {
return f()
return f(r.right)
}

return r.left
Expand Down Expand Up @@ -165,12 +165,12 @@ func (r Result[T]) AndThen(f func(T) Result[T]) Result[T] {
// OrElse returns the original Result if it is a success, otherwise it returns
// the provided alternative Result. This along with AndThen can be used to
// Railway Oriented Programming (ROP).
func (r Result[T]) OrElse(f func() Result[T]) Result[T] {
func (r Result[T]) OrElse(f func(error) Result[T]) Result[T] {
if r.IsOk() {
return r
}

return f()
return f(r.right)
}

// FlatMapResult applies a function that returns a Result[B] to the success
Expand Down

0 comments on commit 9f35664

Please sign in to comment.