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
class JazzBandSpec extends FlatSpec with Matchers{ | |
"Jazz band closure " should " create a musician closure with access to band set list" in { | |
val setList = List("Donna Lee", "Dig") | |
val jazzBandFunctionThatCreatesMusician: List[String] => () => List[String] | |
= JazzBand.jazzBandThatCreatesMusician | |
val musicianFunctionThatCanGetBandSetList: () => List[String] | |
= jazzBandFunctionThatCreatesMusician(setList) | |
musicianFunctionThatCanGetBandSetList() should be (setList) | |
//Re-writing the above in a more idiomatic and simplified way | |
JazzBand.jazzBandThatCreatesMusician(setList)() should be (setList) | |
} | |
} | |
package object JazzBand { | |
def jazzBandThatCreatesMusician(setList: List[String]) | |
= () => setList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment