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 wrapper class for Set #247

Merged
merged 10 commits into from
Sep 10, 2017
Merged

Add wrapper class for Set #247

merged 10 commits into from
Sep 10, 2017

Conversation

victorg1991
Copy link
Contributor

Addressing #203

@codecov-io
Copy link

codecov-io commented Sep 3, 2017

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #247   +/-   ##
=========================================
  Coverage          ?   41.69%           
  Complexity        ?      259           
=========================================
  Files             ?      136           
  Lines             ?     3149           
  Branches          ?      410           
=========================================
  Hits              ?     1313           
  Misses            ?     1710           
  Partials          ?      126
Impacted Files Coverage Δ Complexity Δ
...st/src/main/kotlin/kategory/laws/SemigroupKlaws.kt 16.66% <0%> (ø) 0 <0> (?)
...-test/src/main/kotlin/kategory/laws/MonoidKLaws.kt 7.69% <0%> (ø) 1 <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 539de80...fb0c924. Read the comment docs.

package kategory

@higherkind
@deriving(Monad::class, Traverse::class, MonoidK::class)
Copy link
Member

Choose a reason for hiding this comment

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

Set can't have neither Monad nor Traverse instances. Just Foldable and MonoidK because sets don't guarantee order of iteration and that is why flatMap gives you back an Iterable. We should only have those two mentioned instances

@deriving(Monad::class, Traverse::class, MonoidK::class)
data class SetKW<A>(val set: Set<A>) : SetKWKind<A>, Set<A> by set {

fun <B> flatMap(f: (A) -> SetKWKind<B>): SetKW<B> = this.set.flatMap { f(it).ev().set }.toSet().k()
Copy link
Member

Choose a reason for hiding this comment

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

🔥 remove as this would yield nondeterministic results.

return Eval.defer { loop(this) }
}

fun <G, B> traverse(f: (A) -> HK<G, B>, GA: Applicative<G>): HK<G, SetKW<B>> =
Copy link
Member

Choose a reason for hiding this comment

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

🔥 remove as this would yield nondeterministic results.


fun <B> flatMap(f: (A) -> SetKWKind<B>): SetKW<B> = this.set.flatMap { f(it).ev().set }.toSet().k()

fun <B> map(f: (A) -> B): SetKW<B> = this.set.map(f).toSet().k()
Copy link
Member

Choose a reason for hiding this comment

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

🔥

GA.map2Eval(f(a), eval) { (setOf(it.a) + it.b).k() }
}.value()

fun <B, Z> map2(fb: SetKWKind<B>, f: (Tuple2<A, B>) -> Z): SetKW<Z> =
Copy link
Member

Choose a reason for hiding this comment

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

🔥

}
}

fun <A, B> tailRecM(a: A, f: (A) -> HK<SetKWHK, Either<A, B>>): SetKW<B> {
Copy link
Member

Choose a reason for hiding this comment

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

🔥

return SetKW(buf.toSet())
}

fun functor(): SetKWHKMonadInstance = SetKW.monad()
Copy link
Member

Choose a reason for hiding this comment

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

🔥


fun functor(): SetKWHKMonadInstance = SetKW.monad()

fun applicative(): SetKWHKMonadInstance = SetKW.monad()
Copy link
Member

Choose a reason for hiding this comment

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

🔥

@victorg1991
Copy link
Contributor Author

I've updated the PR with the comments :)

fun <B> foldR(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B> {
fun loop(fa_p: SetKW<A>): Eval<B> = when {
fa_p.set.isEmpty() -> lb
else -> f(fa_p.set.first(), Eval.defer { loop(fa_p.set.drop(1).toSet().k()) })
Copy link
Member

Choose a reason for hiding this comment

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

SetKW.foldR has the same problem like ListKW.foldR related in #240, seems it's a problem of Eval #252

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.

Awesome work, Let's make A covariant in SetKW if possible in the same way is covariant in Set


@higherkind
@deriving(Foldable::class, MonoidK::class)
data class SetKW<A>(val set: Set<A>) : SetKWKind<A>, Set<A> by set {
Copy link
Member

Choose a reason for hiding this comment

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

Can A be covariant here?

@victorg1991
Copy link
Contributor Author

done @raulraja :D thanks for the help

@raulraja
Copy link
Member

@victorg1991 can you remerge master, we changed the modules location

@victorg1991
Copy link
Contributor Author

Done @raulraja 👍

@pakoito pakoito merged commit 3abc0c4 into arrow-kt:master Sep 10, 2017
@victorg1991 victorg1991 deleted the victorg-setkw branch September 10, 2017 10:56
@wiyarmir wiyarmir mentioned this pull request Sep 15, 2017
@pakoito pakoito mentioned this pull request Sep 28, 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.

5 participants