Last active
April 19, 2018 12:48
-
-
Save tabdulradi/81105786ef62345855276962d9d45316 to your computer and use it in GitHub Desktop.
Function that allows values to be discarded in a visible way. Combined with Scalac flags: `-Ywarn-value-discard` (and maybe `-Xfatal-warnings`).
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
scala> ValueDiscard[Int](5) | |
scala> ValueDiscard(5) | |
<console>:12: error: ValueDiscard.type does not take parameters | |
ValueDiscard(5) | |
^ |
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
object ValueDiscard { | |
/** | |
* Function that allows values to be discarded in a visible way. | |
* | |
* @tparam T type of the value that will be computed (it won't be inferred, | |
* must be specified) | |
* @return function accepting value expression that needs to be computed and | |
* whose value will be discarded | |
*/ | |
def apply[T]: (=> T) => Unit = { value => | |
val _ = value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment