Last active
October 27, 2019 02:25
-
-
Save martinmroz/79fed5be8b8d4e0cb968a798afd6fff6 to your computer and use it in GitHub Desktop.
Mapping a single character onto a Flux Monoid
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
impl From<u8> for Flux { | |
fn from(other: u8) -> Self { | |
if other.is_ascii_whitespace() { | |
// A line-feed is considered an ASCII whitespace character by `is_ascii_whitespace`. | |
let lines = if other == ('\n' as u8) { 1 } else { 0 }; | |
Flux::new(CharType::IsSpace, 0, lines, CharType::IsSpace) | |
} else { | |
Flux::new(CharType::NotSpace, 1, 0, CharType::NotSpace) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment