Skip to content

Commit

Permalink
According to wiki, sequence is a better name
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Dec 22, 2024
1 parent 13dd108 commit 24e7065
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/morsey.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type Char {
Invalid(String)
}

pub type Code =
pub type Sequence =
List(Char)

pub type EncodeError {
Expand All @@ -38,15 +38,15 @@ pub fn main() {
}
}

pub fn encode(text: String) -> Result(Code, EncodeError) {
pub fn encode(text: String) -> Result(Sequence, EncodeError) {
let encoded = encode_sentence(text)
case first_invalid_character(encoded) {
Ok(char) -> Error(InvalidCharacter(char))
Error(Nil) -> Ok(encoded)
}
}

pub fn to_string(encoded: Code) -> String {
pub fn to_string(encoded: Sequence) -> String {
encoded
|> list.map(fn(symbol) {
case symbol {
Expand All @@ -60,7 +60,7 @@ pub fn to_string(encoded: Code) -> String {
|> string.join("")
}

pub fn from_string(text: String) -> Code {
pub fn from_string(text: String) -> Sequence {
text
|> string.to_graphemes
|> list.map(fn(x) {
Expand Down Expand Up @@ -111,7 +111,7 @@ fn first_invalid_character(symbols) -> Result(String, Nil) {
|> list.first
}

fn encode_char(char: String) -> Code {
fn encode_char(char: String) -> Sequence {
let char = string.uppercase(char)
let encode_map = dict.from_list(map())
case encode_map |> dict.get(char) {
Expand All @@ -120,7 +120,7 @@ fn encode_char(char: String) -> Code {
}
}

fn encode_word(word: String) -> Code {
fn encode_word(word: String) -> Sequence {
let encoded =
string.to_graphemes(word)
|> list.map(encode_char)
Expand All @@ -129,7 +129,7 @@ fn encode_word(word: String) -> Code {
list.take(encoded, list.length(encoded) - 1)
}

fn encode_sentence(sentence: String) -> Code {
fn encode_sentence(sentence: String) -> Sequence {
let encoded =
sentence
|> string.split(" ")
Expand Down

0 comments on commit 24e7065

Please sign in to comment.