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

#841 - Add Monoid instances #942

Merged
merged 8 commits into from
Jul 19, 2018
Merged

#841 - Add Monoid instances #942

merged 8 commits into from
Jul 19, 2018

Conversation

bassjacob
Copy link
Contributor

Adding this as a WIP for now. Would there be more required for Try/Either?

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great so far, let us know when this is ready for final review, thanks!

interface EitherMonoidInstance<L, R> : EitherSemigroupInstance<L, R>, Monoid<Either<L, R>> {
fun MO(): Monoid<R>

override fun SG(): Semigroup<R> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit pick, favor simple expressions whenever possible:

override fun SG(): Semigroup<R> = MO()

interface TryMonoidInstance<A> : TrySemigroupInstance<A>, Monoid<Try<A>> {
fun MO(): Monoid<A>

override fun SG(): Semigroup<A> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit pick, favor simple expressions whenever possible:

override fun SG(): Semigroup<A> = MO()

is Either.Left -> this
is Either.Right -> { val x = this.b; when (b) {
is Either.Left -> b
is Either.Right -> Either.Right(SG().run { x.combine(b.b) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done without the intermediate variable as this.b.combine(b.b)?

fun SG(): Semigroup<A>

override fun Try<A>.combine(b: Try<A>): Try<A> =
when (this) {
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 move these functions to the datatype, reference them here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to do that given the dependency on SG and the semigroup interface. Is there a good example to follow given that core doesn't import typeclasses to avoid a circular dependency?

@@ -1,11 +1,56 @@
package arrow.instances

import arrow.Kind
import arrow.core.*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why my editor is making that change, but I can revert if you'd like?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, although it isn't a blocker.

@codecov
Copy link

codecov bot commented Jul 18, 2018

Codecov Report

Merging #942 into master will increase coverage by 0.1%.
The diff coverage is 75%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #942     +/-   ##
===========================================
+ Coverage     45.42%   45.52%   +0.1%     
  Complexity      647      647             
===========================================
  Files           309      309             
  Lines          7975     7997     +22     
  Branches        859      869     +10     
===========================================
+ Hits           3623     3641     +18     
  Misses         4035     4035             
- Partials        317      321      +4
Impacted Files Coverage Δ Complexity Δ
...tances-core/src/main/kotlin/arrow/instances/try.kt 65.11% <75%> (+3.35%) 0 <0> (ø) ⬇️
...ces-core/src/main/kotlin/arrow/instances/either.kt 68.18% <75%> (+3.66%) 0 <0> (ø) ⬇️
...ics/src/main/kotlin/arrow/optics/instances/mapk.kt 90.9% <0%> (+4.54%) 0% <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 efa0fba...6c64e3c. Read the comment docs.

@pakoito
Copy link
Member

pakoito commented Jul 19, 2018

So far so good. Tell us when it's ready to review!

Copy link
Member

@pakoito pakoito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

@pakoito pakoito merged commit aea5fcc into arrow-kt:master Jul 19, 2018
@bassjacob bassjacob deleted the 841 branch July 19, 2018 22:34
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.

3 participants