Last active
August 29, 2015 13:57
-
-
Save chemist/9482324 to your computer and use it in GitHub Desktop.
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
module Main where | |
import qualified Data.Map as Map | |
import Data.Either (lefts, rights) | |
data DbColumn = DbColumn { name :: String | |
, tableName :: TableName | |
} deriving Show | |
newtype TableName = TableName String deriving (Ord, Eq, Show) | |
type Config = Map.Map TableName [DbColumn] | |
doWork :: Config -> [DbColumn] -> [Either String DbColumn] | |
doWork conf input = concatMap (fun conf) input | |
where | |
fun conf x@(DbColumn "id" _) = [Right x] | |
fun conf (DbColumn _ tn) = case Map.lookup tn conf of | |
Just x -> fmap Right x | |
Nothing -> [Left $ "id for table " ++ show tn ++ " not found in conf"] | |
good :: [Either String DbColumn] -> [DbColumn] | |
good = rights | |
bad :: [Either String DbColumn] -> [String] | |
bad = lefts | |
main :: IO () | |
main = do | |
let result = doWork undefined undefined | |
print $ "good " ++ (show $ good result) | |
print $ "bad " ++ (show $ bad result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment