-
-
Save rightfold/2251472e0ee490a38605c118373d156a to your computer and use it in GitHub Desktop.
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
readRational :: String -> Maybe Rational | |
readRational = (<|>) <$> withPoint <*> withSlash | |
where | |
withPoint = | |
String.split (String.Pattern ".") | |
>>> traverse Int.fromString | |
>=> case _ of | |
[a] -> Just $ a % 1 | |
[a, b] -> Just $ a % 1 + b % 10 | |
_ -> Nothing | |
withSlash = | |
String.split (String.Pattern "/") | |
>>> traverse Int.fromString | |
>=> case _ of | |
[a] -> Just $ a % 1 | |
[a, b] -> Just $ a % b | |
_ -> Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment