-
Notifications
You must be signed in to change notification settings - Fork 98
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
Make Predicate stack-safe using Eval #283
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b00c4c9
Predicate: add benchmark
fc6bacc
Predicate: stack safety tests
76069db
Make Predicate stack-safe using Eval
cadc03c
Avoid trivial benchmarks and safety tests
f71a3bd
Use Predicate.empty where applicable
47d5786
Improve ArbitraryPredicate
d0df5ec
Add Bool[Predicate[A]]
2e93fce
Predicate: use Eval static instances
77e0628
PredicateInstances: fix naming of implicits
94604fb
PredicateSpec: increase comparion sample size
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cats.collections | ||
package bench | ||
|
||
import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, Setup, State} | ||
import cats._ | ||
import cats.implicits._ | ||
|
||
@State(Scope.Benchmark) | ||
class ChainedPredicateBench { | ||
@Param(Array("10", "100", "1000", "10000")) | ||
var n: Int = _ | ||
|
||
var pred: Predicate[Int] = _ | ||
|
||
@Setup | ||
def setup: Unit = { | ||
pred = Predicate(_ == 0) | ||
pred = Iterator.iterate(pred.negate)(_ - pred).drop(n).next() | ||
} | ||
|
||
@Benchmark | ||
def catsCollectionsPredicateUnravel: Unit = { | ||
pred.contains(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
scalacheck/src/main/scala/cats/collections/arbitrary/ArbitraryPredicate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
package cats.collections | ||
package arbitrary | ||
|
||
import org.scalacheck.{Gen, Arbitrary} | ||
import cats.Order | ||
import org.scalacheck.{Gen, Cogen, Arbitrary} | ||
|
||
trait ArbitraryPredicate { | ||
import set._ | ||
def predicateGen[A: Arbitrary: Order]: Gen[Predicate[A]] = | ||
setGen.map(_.predicate) | ||
import Gen._ | ||
def predicateGen[A: Arbitrary: Cogen]: Gen[Predicate[A]] = | ||
oneOf(const(Predicate.empty), const(Predicate.everything), resultOf(Predicate(_: A => Boolean))) | ||
|
||
implicit def predicateArbitrary[A: Arbitrary: Order]: Arbitrary[Predicate[A]] = | ||
implicit def predicateArbitrary[A: Arbitrary: Cogen]: Arbitrary[Predicate[A]] = | ||
Arbitrary(predicateGen[A]) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what about a
def fromKleisli[A](k: Kleisli[Eval, A, Boolean]): Predicate[A] = Lift(k)