Skip to content

Instantly share code, notes, and snippets.

@rasmusmerzin
Created December 10, 2020 23:36
Show Gist options
  • Save rasmusmerzin/fe335ca7ef4c0a1a3bc161fdaf86e4cf to your computer and use it in GitHub Desktop.
Save rasmusmerzin/fe335ca7ef4c0a1a3bc161fdaf86e4cf to your computer and use it in GitHub Desktop.
#[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