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

fix #1398 #1409

Merged
merged 1 commit into from Jun 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions core/src/main/scala/scalaz/Foldable.scala
Expand Up @@ -253,9 +253,20 @@ trait Foldable[F[_]] { self =>
} {
case (x @ ((amin, amax, bmin, bmax)), a) =>
val b = f(a)
if (Order[B].order(b, bmin) == LT) (a, amax, b, bmax)
else if (Order[B].order(b, bmax) == GT) (amin, a, bmin, b)
else x
val greaterThanOrEq = Order[B].greaterThanOrEqual(b, bmax)
if(Order[B].lessThanOrEqual(b, bmin)) {
if(greaterThanOrEq) {
(a, a, b, b)
} else {
(a, amax, b, bmax)
}
} else {
if(greaterThanOrEq) {
(amin, a, bmin, b)
} else {
x
}
}
} map {
case (amin, amax, _, _) => (amin, amax)
}
Expand Down
11 changes: 9 additions & 2 deletions tests/src/test/scala/scalaz/FoldableTest.scala
Expand Up @@ -69,10 +69,17 @@ object FoldableTest extends SpecLite {
(xs extremaOf f) must_== (xs minimumOf f).tuple(xs maximumOf f)
}
"extremaBy" ! forAll {
(xs: List[Int]) =>
val f: Int => Double = 1D + _
(xs: List[Int], f: Int => Int) =>
(xs extremaBy f) must_== (xs minimumBy f).tuple(xs maximumBy f)
}
"extremaBy consistent with minimumBy/maximumBy" ! {
val xs = (1 to 6).toList
val f: Int => Int = _ % 3
(xs extremaBy f) must_== (xs minimumBy f).tuple(xs maximumBy f)

val g: Int => Int = _ => 0
(xs extremaBy g) must_== (xs minimumBy g).tuple(xs maximumBy g)
}

"distinct" ! forAll {
(xs: List[Int]) =>
Expand Down