Skip to content

Instantly share code, notes, and snippets.

@EncodePanda
Last active August 29, 2015 14:22
Show Gist options
  • Save EncodePanda/1fdfda27931aa687710b to your computer and use it in GitHub Desktop.
Save EncodePanda/1fdfda27931aa687710b to your computer and use it in GitHub Desktop.
How to combine functionalities?
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