Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ApplicativeError#catch have bias to the right #1063

Merged
merged 1 commit into from Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,13 +26,13 @@ interface ApplicativeError<F, E> : Applicative<F> {
fun <A> fromEither(fab: Either<E, A>): Kind<F, A> =
fab.fold({ raiseError<A>(it) }, { just(it) })

fun <A> catch(f: () -> A, recover: (Throwable) -> E): Kind<F, A> =
fun <A> catch(recover: (Throwable) -> E, f: () -> A): Kind<F, A> =
try {
just(f())
} catch (t: Throwable) {
raiseError<A>(recover(t))
}

fun <A> ApplicativeError<F, Throwable>.catch(f: () -> A): Kind<F, A> =
catch(f, ::identity)
catch(::identity, f)
}
Expand Up @@ -111,11 +111,11 @@ Constructor function. It takes two function parameters. The first is a generator
`catch()` runs the generator function to generate a success datatype, and if it throws an exception it uses the error mapping function to create a new failure datatype.

```kotlin:ank
eitherAE.catch({ 1 } ,::identity)
eitherAE.catch(::identity) { 1 }
```

```kotlin:ank
eitherAE.catch({ throw RuntimeException("Boom") } ,::identity)
eitherAE.catch(::identity) { throw RuntimeException("Boom") }
```

### Laws
Expand Down