Override Foldable methods#1532
Conversation
Codecov Report@@ Coverage Diff @@
## master #1532 +/- ##
==========================================
+ Coverage 92.26% 92.48% +0.21%
==========================================
Files 246 246
Lines 3764 3885 +121
Branches 125 133 +8
==========================================
+ Hits 3473 3593 +120
- Misses 291 292 +1
Continue to review full report at Codecov.
|
- Override Foldable methods in a lot of instances (including NonEmptyReducible) - Override MonoidK algebra to get kernel Monoid instance - Add Reducible for Tuple2 I might have gone overboard with the "one element foldables" (Option, Either, ...).
8549619 to
0f6775d
Compare
johnynek
left a comment
There was a problem hiding this comment.
that extension shows you what is untested. Seems like we need to enhance the laws here.
I really like this PR though, since it affords some chances for optimizations, which is nice.
| a :: G.toList(ga) | ||
| } | ||
|
|
||
| override def toNonEmptyList[A](fa: F[A]): NonEmptyList[A] = { |
There was a problem hiding this comment.
this method code path is untested
| fa.reduce | ||
|
|
||
| override def foldM[G[_], A, B](fa: NonEmptyVector[A], z: B)(f: (B, A) => G[B])(implicit G: Monad[G]): G[B] = | ||
| Foldable.iteratorFoldM(fa.toVector.toIterator, z)(f) |
| } | ||
| def raiseError[A](e: E): Validated[E, A] = Validated.Invalid(e) | ||
|
|
||
| override def reduceLeftToOption[A, B](fa: Validated[E, A])(f: A => B)(g: (B, A) => B): Option[B] = |
| fa.forall(p) | ||
|
|
||
| override def toList[A](fa: Validated[E, A]): List[A] = | ||
| fa.fold(_ => Nil, _ :: Nil) |
| override def ensure[B](fab: Either[A, B])(error: => A)(predicate: B => Boolean): Either[A, B] = | ||
| fab.ensure(error)(predicate) | ||
|
|
||
| override def reduceLeftToOption[B, C](fab: Either[A, B])(f: B => C)(g: (C, B) => C): Option[C] = |
| fab.right.forall(p) | ||
|
|
||
| override def toList[B](fab: Either[A, B]): List[B] = | ||
| fab.fold(_ => Nil, _ :: Nil) |
| override def filter[A](fa: Option[A])(p: A => Boolean): Option[A] = | ||
| fa.filter(p) | ||
|
|
||
| override def reduceLeftToOption[A, B](fa: Option[A])(f: A => B)(g: (B, A) => B): Option[B] = |
|
|
||
| override def toList[A](fa: Option[A]): List[A] = fa.toList | ||
|
|
||
| override def filter_[A](fa: Option[A])(p: A => Boolean): List[A] = |
04bbbdd to
75580ba
Compare
|
Improved the test coverage, only the methods |
johnynek
left a comment
There was a problem hiding this comment.
This is great. Thanks for beefing up the tests and optimizing a bit!
|
I think the code is reasonable, especially now that we have full test coverage. |
|
I concur that some benchmarking would be nice to make these performance/complexity decisions. |
|
merging with two thumb ups. |
Foldablemethods in a lot of instances (includingReducibleandNonEmptyReducible)MonoidK#algebraforList,Vector, etc to get kernelMonoidinstanceReducibleforTuple2I might have gone a bit overboard with overriding in the "one element
Foldable" instances (Option,Either, ...).