Current section
Files
Jump to
Current section
Files
src/rna_transcription.gleam
//// Convert DNA to RNA
import gleam/list
import gleam/result
import gleam/string
/// A function that accepts dna as a string and
/// returns a Result with either rna as a string or Nil
pub fn to_rna(dna: String) -> Result(String, Nil) {
dna
|> string.to_graphemes
|> list.try_map(complement)
|> result.map(string.concat)
}
/// A helper function that accepts a char for DNA and
/// returns a Result of a char or Nil
fn complement(nucleotide: String) -> Result(String, Nil) {
case nucleotide {
"C" -> Ok("G")
"G" -> Ok("C")
"T" -> Ok("A")
"A" -> Ok("U")
_ -> Error(Nil)
}
}