-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change return type of RNA transcription to Maybe
- Error case is now defined, eliminating the desire to throw an `error` for invalid input. - The test and example solution are more idiomatic to Haskell, using a `Maybe`. Closes #166
- Loading branch information
1 parent
62fc8a7
commit 3a3ce84
Showing
3 changed files
with
27 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module DNA (toRNA) where | ||
|
||
-- | if string contains invalid character, return Nothing | ||
-- | if string contains only valid nucleotides, return Just transcription | ||
toRNA :: String -> Maybe String | ||
toRNA = undefined |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
module DNA (toRNA) where | ||
|
||
toRNA :: String -> String | ||
toRNA = map $ \c -> case c of | ||
'C' -> 'G' | ||
'G' -> 'C' | ||
'A' -> 'U' | ||
'T' -> 'A' | ||
_ -> error $ "Invalid DNA-base: " ++ show c | ||
import qualified Data.Map.Strict as Map | ||
|
||
toRNA :: String -> Maybe String | ||
toRNA = mapM (`Map.lookup` rna) | ||
where | ||
rna = Map.fromList [ ('C', 'G') | ||
, ('G', 'C') | ||
, ('A', 'U') | ||
, ('T', 'A') ] | ||
|
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