Skip to content

Commit

Permalink
Adding Result#map and Result#mapErr methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kengorab committed Nov 3, 2024
1 parent 4d8f2d1 commit 80bfc5d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions projects/std/src/prelude.abra
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func Some<T>(value: T): Option<T> = Option.Some(value)
export enum Result<V, E> {
Ok(value: V)
Err(error: E)

func map<U>(self, fn: (V) => U): Result<U, E> = match self { Ok(v) => Ok(fn(v)), Err(e) => Err(e) }
func mapErr<F>(self, fn: (E) => F): Result<V, F> = match self { Ok(v) => Ok(v), Err(e) => Err(fn(e)) }
}

func Ok<V, E>(value: V): Result<V, E> = Result.Ok(value)
Expand Down

0 comments on commit 80bfc5d

Please sign in to comment.