-
Notifications
You must be signed in to change notification settings - Fork 454
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 for SortedMap #451
Conversation
fun <G, B> traverse(f: (A) -> HK<G, B>, GA: Applicative<G>): HK<G, SortedMapKW<K, B>> = | ||
Foldable.iterateRight(this.map.iterator(), Eval.always { GA.pure(sortedMapOf<K, B>().k()) })({ | ||
kv, lbuf -> | ||
GA.map2Eval(f(kv.value), lbuf) { (sortedMapOf(kv.key to it.a).k() + it.b).toSortedMap().k() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to sort it afterwards, is there any perf gain from using (mapOf(kv.key to it.a).k() + it.b)
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know, but there's no need for the first map to be sorted if we are sorting it right after as you say. I'm changing this 👍
|
||
fun <K: Comparable<K>, A> SortedMap<K, A>.k(): SortedMapKW<K, A> = SortedMapKW(this) | ||
|
||
fun <K: Comparable<K>, A> Option<Tuple2<K, A>>.k(): SortedMapKW<K, A> = when (this) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using fold instead of when.
@Cotel just wanna say so far it's looking awesome, thanks so much for your contribution! |
import java.util.* | ||
|
||
@higherkind | ||
data class SortedMapKW<K: Comparable<K>, A>(val map: SortedMap<K, A>) : SortedMapKWKind<K, A>, SortedMap<K, A> by map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to follow here the K, V
instead of A, B
we should rename A
for V
so it denotes we refer to the value associated to a key otherwise use A, B
which is the Kategory convention for applied types that are not in higher kind position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know A, B
was the convention. I will change it 👌
|
||
val monoid = SortedMapKW.monoid<String, Int>(SG) | ||
|
||
"Monoid Laws: identity" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be wrong in Map too. This should be tested using MonoidLaws.laws rather than in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pakoito we only have MonoidkLaws :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should then add Monoid and Semigroup laws before merging this. @Cotel wanna take care of those in this PR as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try 💪
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: newline at the end of the file
@Cotel Weeee, thank you for the PR :D |
Thank you for your feedback. I hope this to be the first of many contributions 😃 |
Codecov Report
@@ Coverage Diff @@
## master #451 +/- ##
============================================
+ Coverage 36.07% 36.11% +0.04%
- Complexity 320 327 +7
============================================
Files 174 178 +4
Lines 4846 4901 +55
Branches 523 523
============================================
+ Hits 1748 1770 +22
- Misses 2950 2982 +32
- Partials 148 149 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approval for the PR. I won't merge until I get thumbs up for the new laws!
I've added an implementation for |
@Cotel SortedMap does not provide instances for |
Attempt to solve #205
It is almost the same code as in #310 except this time we are using
SortedMap
.I'm trying to change the tests to be more like
ListKW
ones so this is still WIP 😄