Created
May 25, 2018 06:37
-
-
Save jchia/d785c6dfaea8dfd6745a3315b2ce70d1 to your computer and use it in GitHub Desktop.
Guards
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
| data MappingRow = MappingRow { date :: Date, prod :: Sym, tenor1v :: Sym, tenor2v :: Sym } deriving Show | |
| convertRow :: [MySQLValue] -> IO MappingRow | |
| convertRow sqlRow = eitherStrToMonadError $ | |
| -- I have to define some otherwise-useless x just so that I can use guards. Is there a better way? | |
| -- Why is the syntax for guards so restrictive? | |
| let x | |
| | [MySQLInt32U date, MySQLText prod, MySQLInt16U tenor1v, MySQLInt16U tenor2v] <- sqlRow = do | |
| prod' <- maybeToEither "Bad symbol" $ symFromStrMay prod | |
| let (tenor1v', tenor2v') = | |
| (tenor1v, tenor2v) & each %~ (prod' <>) . symFromStrEx . sformat (left 4 '0') | |
| pure $ MappingRow (yyyymmdd . fromIntegral $ date) prod' tenor1v' tenor2v' | |
| | otherwise = fail "Bad column count or column types" | |
| in x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment