Created
October 31, 2014 12:19
-
-
Save 2m/d09b74ba379898a4f01e to your computer and use it in GitHub Desktop.
Ciklas cikle
This file contains hidden or 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
case class Request(valid: Boolean, impressions: Seq[Impression]) | |
case class Impression(rules: Seq[Rule]) | |
case class Rule(valid: Boolean) | |
case class Bid(money: Double) | |
// generate some random requests | |
val requests = Vector.fill(5) { | |
Request( | |
scala.util.Random.nextBoolean, | |
Vector.fill(3) { | |
Impression( | |
Vector.fill(2) { | |
Rule(scala.util.Random.nextBoolean) | |
} | |
) | |
} | |
) | |
} | |
// `for` in scala is just a sugar for flatMap and filter. | |
val processed = for { | |
request <- requests.filter(_.valid == true) | |
impression <- request.impressions | |
rule <- impression.rules | |
if rule.valid | |
} yield { | |
Bid(123) | |
} | |
println(s"Processed valid requests $processed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment