Skip to content

Instantly share code, notes, and snippets.

@chemist
Last active August 29, 2015 13:57
Show Gist options
  • Save chemist/9482324 to your computer and use it in GitHub Desktop.
Save chemist/9482324 to your computer and use it in GitHub Desktop.
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