Skip to content

Commit

Permalink
Added lazy repeater solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
jusexton committed Jul 7, 2024
1 parent 028e095 commit d96e0e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ other languages.
- Fibonacci Product (https://www.codewars.com/kata/5541f58a944b85ce6d00006a)
- Valid Parentheses (https://www.codewars.com/kata/52774a314c2333f0a7000688)
- Alphanumeric (https://www.codewars.com/kata/526dbd6c8c0eb53254000110)
- Lazy Repeater (https://www.codewars.com/kata/51fc3beb41ecc97ee20000c3)

#### Kata 6

Expand Down
18 changes: 18 additions & 0 deletions src/codewars/lazy_repeater.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fn make_looper(s: &str) -> impl FnMut() -> char + '_ {
let mut char_looper = s.chars().cycle();
move || char_looper.next().unwrap()
}

#[cfg(test)]
mod tests {
use super::make_looper;

#[test]
fn test_looper_correctly_loops_over_given_characters() {
let mut looper = make_looper("abc");
assert_eq!('a', looper());
assert_eq!('b', looper());
assert_eq!('c', looper());
assert_eq!('a', looper());
}
}
1 change: 1 addition & 0 deletions src/codewars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ mod summation;
mod sumpairs;
mod valid_parentheses;
mod valid_spacing;
mod lazy_repeater;

0 comments on commit d96e0e8

Please sign in to comment.