Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package object collection {
- /**
- * Provides extra util methods for the [[Traversable]] class.
- *
- * @param traversable The [[Traversable]] to enrich.
- * @tparam A The [[Traversable]] type parameter.
- */
- implicit class RichTraversable[+A](traversable: Traversable[A]) {
- /**
- * Groups the traversable by the criteria specified by ``groupBy`` and then filters each
- * group by the minimum element according to ``minBy``.
- *
- * @param groupBy The group by function.
- * @param minBy The min by function.
- * @param cmp An implicit ordering for ``B``.
- * @tparam K The type for the groups keys.
- * @tparam B The resulting type of the min by function.
- * @return The traversable with the minimum elements of each group.
- */
- def groupByAndFilterMin[K, B](groupBy: A => K, minBy: A => B)
- (implicit cmp: Ordering[B]): Traversable[A] =
- traversable.groupBy(groupBy).mapValues(_.minBy(minBy)).values.toSeq
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement