Created
July 18, 2011 18:23
-
-
Save davetron5000/1090237 to your computer and use it in GitHub Desktop.
Object.tap for Scala?
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
object Tapper { | |
implicit def anyToTapper[A](obj: A) = new Tapper(obj) | |
} | |
class Tapper[A](obj: A) { | |
def tap(code: A => Unit): A = { | |
code(obj) | |
obj | |
} | |
} |
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
import Tapper._ | |
createMock(classOf[CurrencyService]).tap { service => | |
expect(service.getCurrencySymbol(utilityAccount)).andReturn("$") | |
replay(service) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment