DEV Community

Discussion on: Daily Challenge #175 - Complementary DNA

Collapse
 
craigmc08 profile image
Craig McIlwrath • Edited

Haskell:

complement :: Char -> Either String Char
complement 'A' = Right 'T'
complement 'T' = Right 'A' 
complement 'C' = Right 'G' 
complement 'G' = Right 'C' 
complement c = Left $ "invalid nucleic acid " ++ [c]

dnaStrand :: String -> Either String String 
dnaStrand = sequence . map complement

Returns a Left value if there is a character other than AGTC