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

Kleisli and EitherT extra instances and tests + some fixes #127

Merged
merged 2 commits into from
Jul 16, 2017

Conversation

raulraja
Copy link
Member

No description provided.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@01bdd2a). Click here to learn what that means.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #127   +/-   ##
=========================================
  Coverage          ?   55.85%           
  Complexity        ?      212           
=========================================
  Files             ?       90           
  Lines             ?     1332           
  Branches          ?      173           
=========================================
  Hits              ?      744           
  Misses            ?      514           
  Partials          ?       74
Impacted Files Coverage Δ Complexity Δ
.../src/main/kotlin/kategory/typeclasses/Typeclass.kt 56.52% <ø> (ø) 0 <0> (?)
...src/main/kotlin/kategory/typeclasses/MonadError.kt 81.81% <0%> (ø) 0 <0> (?)
...in/kotlin/kategory/typeclasses/ApplicativeError.kt 0% <0%> (ø) 0 <0> (?)
...rc/main/kotlin/kategory/typeclasses/MonadReader.kt 0% <0%> (ø) 0 <0> (?)
kategory/src/main/kotlin/kategory/data/Kleisli.kt 69.69% <57.14%> (ø) 8 <0> (?)
kategory/src/main/kotlin/kategory/data/EitherT.kt 54.54% <65%> (ø) 6 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01bdd2a...d4ef37d. Read the comment docs.

@pakoito pakoito self-requested a review July 16, 2017 17:39
@raulraja raulraja merged commit b8e962f into master Jul 16, 2017
@raulraja raulraja deleted the rr-kleisli-instances branch July 16, 2017 17:42
@@ -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
Copy link
Member

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>> {
Copy link
Member

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
Copy link
Member

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> =
Copy link
Member

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)
Copy link
Member

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 =

@pakoito pakoito mentioned this pull request Jul 16, 2017
@wiyarmir wiyarmir mentioned this pull request Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants