-
Notifications
You must be signed in to change notification settings - Fork 449
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
Kleisli and EitherT extra instances and tests + some fixes #127
Conversation
# Conflicts: # kategory/src/test/kotlin/kategory/data/EitherTTest.kt
Codecov Report
@@ Coverage Diff @@
## master #127 +/- ##
=========================================
Coverage ? 55.85%
Complexity ? 212
=========================================
Files ? 90
Lines ? 1332
Branches ? 173
=========================================
Hits ? 744
Misses ? 514
Partials ? 74
Continue to review full report at Codecov.
|
@@ -78,3 +78,51 @@ data class EitherT<F, A, B>(val MF: Monad<F>, val value: HK<F, Either<A, B>>) : | |||
return GA.map(fa, { EitherT(MF, MF.map(it.lower(), { it.ev() })) }) | |||
} | |||
} | |||
|
|||
class EitherTInstances<F, L>(val MF : Monad<F>) : EitherTMonadError<F, L> { | |||
override fun MF(): Monad<F> = MF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class requires a inline fun invoke constructor in the companion object that defaults the MF monad.
override fun MF(): Monad<F> = MF | ||
} | ||
|
||
interface EitherTMonad<F, L> : Monad<EitherTF<F, L>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we kept all instances together, yet still on a separate file. Open for discussing pros/cons.
class KleisliInstances<F, D, E>(val FME: MonadError<F, E>) : KleisliMonadReader<F, D>, KleisliMonadError<F, D, E> { | ||
override fun FM(): Monad<F> = FME | ||
|
||
override fun FME(): MonadError<F, E> = FME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
fun <A> fromEither(fab: Either<E, A>): HK<F, A> = | ||
fab.fold({ raiseError<A>(it) }, { pure(it) }) | ||
|
||
fun <A> catch(f: () -> A, recover: (Throwable) -> E): HK<F, A> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this function be inlined?
fun <A> local(f: (D) -> D, fa: HK<F, A>): HK<F, A> | ||
|
||
/** Retrieves a function of the environment */ | ||
fun <A> reader(f: (D) -> A): HK<F, A> = map(ask(), f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Formatting even for short methods is to have a new line after the =
No description provided.