Created
April 10, 2016 20:12
-
-
Save malcolmgreaves/cc17399bd8077882946ddedeea8da3d2 to your computer and use it in GitHub Desktop.
Adds a convenient method to perform a side effect and evaluate to the (originally called) value.
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
| implicit class ChainSideEffect[T](private val x: T) extends AnyVal { | |
| @inline def sideEffect(op: () => Unit): T = { | |
| val _: Unit = op() | |
| x | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this implicit class + method to solve a problem I had earlier today. My code looked like the following: