Created
June 15, 2017 06:55
-
-
Save anonymous/1d9324137f5ac8fdce713bf8d3f4ca05 to your computer and use it in GitHub Desktop.
the description for this gist
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
val regex = "(-?[1-9][0-9]*)|0".r | |
val stringToIntPrism = Prism[String, Int]{ str => | |
if(regex.pattern.matcher(str).matches) { | |
Try(str.toInt).toOption | |
} else { | |
None | |
} | |
}(_.toString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment