Last active
August 29, 2015 14:22
-
-
Save EncodePanda/1fdfda27931aa687710b to your computer and use it in GitHub Desktop.
How to combine functionalities?
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
A: | |
trait DoValidator { | |
def validate(input:String): Validation = ... | |
} | |
trait Doer extends DoValidator { | |
def do(input: String) = validate(input) match | |
case Success => .... | |
case Failuer => .... | |
} | |
with tests like: | |
trait AlwaysFailValidation extends DoerValidator { | |
def validate(input:String) = Failuer() | |
} | |
test("that will handle failuers") { | |
// given | |
val doer: Doer with AlwaysFailValidation() {} | |
// when | |
doer.do("some input") | |
// then | |
.... | |
} | |
OR | |
B: | |
trait Doer { | |
def do(input: String)(validate: String=>Validation) = validate(input) match | |
case Success => .... | |
case Failuer => .... | |
} | |
with tests like: | |
test("that will handle failuers") { | |
// when | |
doer.do("some input")(v => Failuer) | |
// then | |
.... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment