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 and instances for Sequence #241

Merged
merged 7 commits into from
Sep 4, 2017
Merged

Conversation

pt2121
Copy link
Contributor

@pt2121 pt2121 commented Sep 2, 2017

addressing #207

@pt2121 pt2121 changed the title Add Traversable and Monoid instances for Sequence Add wrapper and instances for Sequence Sep 2, 2017
@codecov-io
Copy link

codecov-io commented Sep 2, 2017

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #241   +/-   ##
=========================================
  Coverage          ?   49.76%           
  Complexity        ?      240           
=========================================
  Files             ?      113           
  Lines             ?     2526           
  Branches          ?      292           
=========================================
  Hits              ?     1257           
  Misses            ?     1154           
  Partials          ?      115
Impacted Files Coverage Δ Complexity Δ
...main/kotlin/kategory/instances/SequenceKWMonoid.kt 0% <0%> (ø) 0 <0> (?)
...tegory/src/main/kotlin/kategory/data/SequenceKW.kt 70.73% <70.73%> (ø) 7 <7> (?)

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 128f330...1a34582. Read the comment docs.

@raulraja
Copy link
Member

raulraja commented Sep 2, 2017

looking good so far!

@pt2121 pt2121 force-pushed the pt/sequence branch 2 times, most recently from 369a723 to 347ae0d Compare September 2, 2017 18:07
}

testLaws(SemigroupKLaws.laws(SequenceKW.semigroupK(), applicative, eq))
testLaws(MonoidKLaws.laws(SequenceKW.monoidK(), applicative, eq))
Copy link
Member

Choose a reason for hiding this comment

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

init {
val eq: Eq<HK<SequenceKWHK, Int>> = object : Eq<HK<SequenceKWHK, Int>> {
override fun eqv(a: HK<SequenceKWHK, Int>, b: HK<SequenceKWHK, Int>): Boolean =
a.ev().sequence.toList() == b.ev().sequence.toList()
Copy link
Member

@pakoito pakoito Sep 3, 2017

Choose a reason for hiding this comment

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

It'd be great to move .ev().sequence.toList() to an extension function, so it can be called directly like in here.

See: https://github.com/kategory/kategory/blob/master/kategory/src/main/kotlin/kategory/data/Id.kt#L3

@pt2121
Copy link
Contributor Author

pt2121 commented Sep 3, 2017

this's ready for review


fun <A> empty(): SequenceKW<A> = emptySequence<A>().k()

private tailrec fun <A, B> go(
Copy link
Member

Choose a reason for hiding this comment

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

NIT: We generally want these functions as internal functions inside tailrecM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will fix

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.

Awesome first PR. SO clean!

Copy link
Member

@tonilopezmr tonilopezmr left a comment

Choose a reason for hiding this comment

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

Well done 💯

fun <B> foldR(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B> {
fun loop(fa_p: SequenceKW<A>): Eval<B> = when {
fa_p.sequence.none() -> lb
else -> f(fa_p.ev().sequence.first(), Eval.defer { loop(fa_p.sequence.drop(1).k()) })
Copy link
Member

Choose a reason for hiding this comment

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

one question also to @pakoito,

  1. Why not use fa_p.ev().first() or fa_p.drop(1).k() instead ?
  2. Why do you use ev() method only for fa_p.ev().sequence.first() and not for drop?
  3. Is it necessary to use evidence method (ev()) here?

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 think f(fa_p.first(), Eval.defer { loop(fa_p.drop(1).k()) }) works as well. i don't have a strong opinion on this. up to you guys

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's works because you are delegating all public val sequence: Sequence<A> methods to SequenceKW

Copy link
Member

Choose a reason for hiding this comment

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

Nits mostly, if @pt2121 wants I'll just go ahead and merge.

Copy link
Contributor Author

@pt2121 pt2121 Sep 4, 2017

Choose a reason for hiding this comment

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

i can update. gimme a couple minutes

@pt2121 pt2121 force-pushed the pt/sequence branch 2 times, most recently from 1d1d2e1 to e74a526 Compare September 4, 2017 17:36
make `go` an inner fun of `tailRecM` and improve foldR implementaion
@pt2121
Copy link
Contributor Author

pt2121 commented Sep 4, 2017

done!
thanks for your review & the cool project
i'm still studying the code/tools but it was fun so far.

@pakoito pakoito merged commit 543bfbd into arrow-kt:master Sep 4, 2017
@pakoito
Copy link
Member

pakoito commented Sep 4, 2017

@pt2121 Thank you for your effort. Happy to look something else in the roadmap for you!

@pt2121 pt2121 deleted the pt/sequence branch September 4, 2017 19:44
@wiyarmir wiyarmir mentioned this pull request Sep 15, 2017
@pt2121 pt2121 mentioned this pull request Oct 8, 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