itertools instead of bespoke
This commit is contained in:
parent
471caeb9c9
commit
5226edbb0a
4 changed files with 18 additions and 35 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -8,6 +8,21 @@ version = "1.0.79"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
|
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.10"
|
version = "1.0.10"
|
||||||
|
@ -19,6 +34,7 @@ name = "lodestone-level-calc-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"itertools",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,5 +7,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
|
itertools = "0.12.1"
|
||||||
serde = { version = "1.0.196", features = ["alloc", "serde_derive"] }
|
serde = { version = "1.0.196", features = ["alloc", "serde_derive"] }
|
||||||
serde_json = { version = "1.0.113", features = ["alloc"] }
|
serde_json = { version = "1.0.113", features = ["alloc"] }
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
mod compile_data;
|
mod compile_data;
|
||||||
mod map_ok;
|
|
||||||
mod raw_data;
|
mod raw_data;
|
||||||
|
|
||||||
use map_ok::MapOkTrait;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::compile_data::{DpsRole, JobStats, Role};
|
use crate::compile_data::{DpsRole, JobStats, Role};
|
||||||
use crate::raw_data::RawJobStats;
|
use crate::raw_data::RawJobStats;
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct MapOkIterator<I, F> {
|
|
||||||
iter: I,
|
|
||||||
f: F,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A, B, E, I, F> Iterator for MapOkIterator<I, F>
|
|
||||||
where
|
|
||||||
F: FnMut(A) -> B,
|
|
||||||
I: Iterator<Item = Result<A, E>>,
|
|
||||||
{
|
|
||||||
type Item = Result<B, E>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.iter.next().map(|x| x.map(&mut self.f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait MapOkTrait {
|
|
||||||
fn map_ok<F, A, B, E>(self, func: F) -> MapOkIterator<Self, F>
|
|
||||||
where
|
|
||||||
Self: Sized + Iterator<Item = Result<A, E>>,
|
|
||||||
F: FnMut(A) -> B,
|
|
||||||
{
|
|
||||||
MapOkIterator {
|
|
||||||
iter: self,
|
|
||||||
f: func,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I, T, E> MapOkTrait for I where I: Sized + Iterator<Item = Result<T, E>> {}
|
|
Loading…
Reference in a new issue