card:impls: *:iter_all and {Rank,Suit}::cards implement Clone.
Bit of a shame, but necessary for using ZipCartesian on them.
This commit is contained in:
@@ -7,7 +7,7 @@ ExactSizeIterator => Map<Range<i64>> is not an ESI. But Range<i32> is an ESI.
|
|||||||
|
|
||||||
impl Rank {
|
impl Rank {
|
||||||
/// Generate an iterator over all ranks.
|
/// Generate an iterator over all ranks.
|
||||||
pub fn iter_all() -> impl ExactSizeIterator<Item = Rank> {
|
pub fn iter_all() -> impl ExactSizeIterator<Item = Rank> + Clone {
|
||||||
(0i32..13)
|
(0i32..13)
|
||||||
.map(|n| n as i64)
|
.map(|n| n as i64)
|
||||||
.map(|n| Rank::try_from(n).unwrap())
|
.map(|n| Rank::try_from(n).unwrap())
|
||||||
@@ -15,7 +15,7 @@ impl Rank {
|
|||||||
|
|
||||||
/// Generate an iterator over all cards within a rank, ordered by Suit. The
|
/// Generate an iterator over all cards within a rank, ordered by Suit. The
|
||||||
/// cards are all default initialised w.r.t. deck (0).
|
/// cards are all default initialised w.r.t. deck (0).
|
||||||
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> {
|
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> + Clone {
|
||||||
let n = self as i32;
|
let n = self as i32;
|
||||||
((n * 4)..((n + 1) * 4)).map(|x| Card::from(x as i64))
|
((n * 4)..((n + 1) * 4)).map(|x| Card::from(x as i64))
|
||||||
}
|
}
|
||||||
@@ -23,13 +23,13 @@ impl Rank {
|
|||||||
|
|
||||||
impl Suit {
|
impl Suit {
|
||||||
/// Generate an iterator over all suits.
|
/// Generate an iterator over all suits.
|
||||||
pub fn iter_all() -> impl ExactSizeIterator<Item = Suit> {
|
pub fn iter_all() -> impl ExactSizeIterator<Item = Suit> + Clone {
|
||||||
(0i32..4).map(|n| Suit::try_from(n as i64).unwrap())
|
(0i32..4).map(|n| Suit::try_from(n as i64).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate an iterator over all cards within a suit, ordered by Rank. The
|
/// Generate an iterator over all cards within a suit, ordered by Rank. The
|
||||||
/// cards are all default initialised in terms of deck (0).
|
/// cards are all default initialised in terms of deck (0).
|
||||||
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> {
|
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> + Clone {
|
||||||
Rank::iter_all().map(move |rank| Card::make_playing_card(0, rank, self))
|
Rank::iter_all().map(move |rank| Card::make_playing_card(0, rank, self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ impl PlayingCard {
|
|||||||
|
|
||||||
/// Generate an iterator over all Playing Cards in the `nth` deck. By
|
/// Generate an iterator over all Playing Cards in the `nth` deck. By
|
||||||
/// construction this is in ascending order.
|
/// construction this is in ascending order.
|
||||||
pub fn iter_all(n: i64) -> impl ExactSizeIterator<Item = Self> {
|
pub fn iter_all(n: i64) -> impl ExactSizeIterator<Item = Self> + Clone {
|
||||||
(0i32..52)
|
(0i32..52)
|
||||||
.map(|x| x as i64)
|
.map(|x| x as i64)
|
||||||
.map(move |x| x + (52 * n))
|
.map(move |x| x + (52 * n))
|
||||||
@@ -95,7 +95,7 @@ impl Card {
|
|||||||
/// order.
|
/// order.
|
||||||
///
|
///
|
||||||
/// Note that each deck gets two jokers.
|
/// Note that each deck gets two jokers.
|
||||||
pub fn iter_all(n: i64) -> impl Iterator<Item = Card> {
|
pub fn iter_all(n: i64) -> impl Iterator<Item = Card> + Clone {
|
||||||
// NOTE: I cannot make this into an ExactSizeIterator using the i32
|
// NOTE: I cannot make this into an ExactSizeIterator using the i32
|
||||||
// trick. Chain<ESI, ESI> is not an ESI, nor is FlatMap<T,U,T->U>
|
// trick. Chain<ESI, ESI> is not an ESI, nor is FlatMap<T,U,T->U>
|
||||||
// (where T and U are ESIs).
|
// (where T and U are ESIs).
|
||||||
|
|||||||
Reference in New Issue
Block a user