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

Add implementation of WriterT and WriterTMonad #85

Merged
merged 7 commits into from
May 4, 2017
Merged

Conversation

pakoito
Copy link
Member

@pakoito pakoito commented Apr 29, 2017

Closes #84

@pakoito
Copy link
Member Author

pakoito commented Apr 29, 2017

Missing: tests. Do not merge yet.

…ption. Add Semigroup instances for NonEmptyList and Number. Add tests for WriterT. Add tests for NumberSemiGroup, OptionMonoid, and NonEmptyListSemiGroup.
@pakoito
Copy link
Member Author

pakoito commented Apr 29, 2017

I went overboard and fixed the Monoid and Semigroup instances.


class NonEmptyListSemigroup<A> : Semigroup<NonEmptyList<A>> {
override fun combine(a: NonEmptyList<A>, b: NonEmptyList<A>): NonEmptyList<A> =
NonEmptyList.fromListUnsafe(a.all + b.all)
Copy link
Member

Choose a reason for hiding this comment

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

This is the same as just a + b

Copy link
Member Author

@pakoito pakoito Apr 29, 2017

Choose a reason for hiding this comment

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

No, the compiler won't pick it up for whatever reason :D

Copy link
Member

Choose a reason for hiding this comment

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

Committed a fix :)

pakoito and others added 3 commits April 29, 2017 16:17
…rly used as they were. Disabled detekt removing Unit return types since it caused the build to fail. Re-applied detekt and fixed formatting.
@codecov
Copy link

codecov bot commented Apr 29, 2017

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #85   +/-   ##
=========================================
  Coverage          ?   43.35%           
  Complexity        ?      104           
=========================================
  Files             ?       51           
  Lines             ?      775           
  Branches          ?      130           
=========================================
  Hits              ?      336           
  Misses            ?      391           
  Partials          ?       48
Impacted Files Coverage Δ Complexity Δ
katz/src/main/kotlin/katz/instances/ListMonoid.kt 0% <ø> (ø) 0 <0> (?)
katz/src/main/kotlin/katz/instances/FloatMonoid.kt 0% <0%> (ø) 0 <0> (?)
...atz/src/main/kotlin/katz/instances/DoubleMonoid.kt 0% <0%> (ø) 0 <0> (?)
katz/src/main/kotlin/katz/instances/ByteMonoid.kt 0% <0%> (ø) 0 <0> (?)
katz/src/main/kotlin/katz/instances/LongMonoid.kt 0% <0%> (ø) 0 <0> (?)
katz/src/main/kotlin/katz/instances/ShortMonoid.kt 0% <0%> (ø) 0 <0> (?)
...rc/main/kotlin/katz/instances/NonEmptyListMonad.kt 80% <0%> (ø) 0 <0> (?)
katz/src/main/kotlin/katz/instances/IntMonoid.kt 100% <100%> (ø) 2 <2> (?)
...ain/kotlin/katz/instances/NonEmptyListSemigroup.kt 100% <100%> (ø) 1 <1> (?)
.../src/main/kotlin/katz/instances/NumberSemigroup.kt 100% <100%> (ø) 1 <1> (?)
... and 5 more

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 ca20458...64e33f3. Read the comment docs.

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.

We should add also MonadWriter and the rest of the MTL style popular typeclasses

@@ -20,7 +20,9 @@ interface Applicative<F> : Functor<F>, Typeclass {
fb.map { fb -> map2(fa, fb, f) }
}

data class Tuple2<out A, out B>(val a: A, val b: B)
data class Tuple2<out A, out B>(val a: A, val b: B) {
fun swap(): Tuple2<B, A> = Tuple2(b, a)
Copy link
Member

Choose a reason for hiding this comment

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

what if we call this reverse and implement it in all Tuple*?

@@ -30,6 +32,10 @@ data class Tuple8<out A, out B, out C, out D, out E, out F, out G, out H>(val a:
data class Tuple9<out A, out B, out C, out D, out E, out F, out G, out H, out I>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F, val g: G, val h: H, val i: I)
data class Tuple10<out A, out B, out C, out D, out E, out F, out G, out H, out I, out J>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F, val g: G, val h: H, val i: I, val j: J)

infix fun <A, B, C, D> Tuple3<A, B, C>.toT(d: D): Tuple4<A, B, C, D> = Tuple4(this.a, this.b, this.c, d)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be plus? Also wondering what a Semigroup instance for each of the tuples looks like ;)

@raulraja raulraja merged commit 33b77a1 into master May 4, 2017
@raulraja raulraja deleted the paco-writert branch May 4, 2017 21:42
ambrusadrianz pushed a commit to ambrusadrianz/arrow that referenced this pull request Oct 22, 2019
* arrow-kt#85: Add Enum encoder and decoder

* arrow-kt#85: Add Enum test

* arrow-kt#85: Add negative tests for enum decoder

* arrow-kt#85: Clean up test names and move the enum code to the correct package

* move enum instances to its companion object

* arrow-kt#85: Add enum section to docs

* arrow-kt#85: Docs formatting

* arrow-kt#85: Combine enum docs fragments

* arrow-kt#85: Import helios.instances.*

* arrow-kt#85: Silence Ank

* arrow-kt#85: Split up section on Enum

* arrow-kt#85: Fix Enum decoder return type

* Update docs/docs/coding/README.md

Co-Authored-By: Adrian Ramirez Fornell <[email protected]>
rachelcarmena pushed a commit that referenced this pull request Feb 24, 2021
* Deprecate extension methods for NonEmptyList

* Move NonEmptyList top-level functions to Lens companion

* Update tests

* Update deprecation message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants