Created
December 10, 2020 23:36
-
-
Save rasmusmerzin/fe335ca7ef4c0a1a3bc161fdaf86e4cf to your computer and use it in GitHub Desktop.
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
#[derive(Debug)] | |
struct Card(bool); | |
impl Card { | |
fn isCompatible(&self) -> bool { | |
self.0 | |
} | |
} | |
struct Vsinder { | |
cards: Vec<Card>, | |
} | |
impl Iterator for Vsinder { | |
type Item = Card; | |
fn next(&mut self) -> Option<Self::Item> { | |
self.cards | |
.pop() | |
.map(|card| match card.isCompatible() { | |
true => Some(card), | |
false => self.next(), | |
}) | |
.flatten() | |
} | |
} | |
fn main() { | |
(Vsinder { | |
cards: vec![Card(false), Card(true), Card(false)], | |
}) | |
.next() | |
.map(|card| println!("{:?}", card)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment