[no description]
cutting edge innovation
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | build.rs | 13 | ||||
| -rw-r--r-- | src/iterator.rs | 64 | ||||
| -rw-r--r-- | src/lib.rs | 11 |
4 files changed, 89 insertions, 1 deletions
@@ -1,6 +1,6 @@ [package] name = "ttools" -version = "0.1.0" +version = "0.1.1" license = "MIT" edition = "2024" authors = ["bend-n <[email protected]>"] @@ -70,6 +70,11 @@ fn generate( type At = {at}; type L = ({left}); type R = ({right}); + type Delete = ({left} /* */ {right}); + fn delete(({left}): Self::L, ({right}): Self::R) -> Self::Delete \ + {{ + ({left} {right}) + }} fn repick(({left}): Self::L, at: Self::At, ({right}): Self::R) -> \ Self {{ ({left} at, {right}) @@ -79,6 +84,14 @@ fn generate( (({left}), {at}, ({right})) }} }} + + impl<{tupl} Z> RePick<{i}, Z> for ({tupl}) {{ + type New = ({left} Z, {right}); + fn unpick(({left}): Self::L, at: Z, ({right}): Self::R) -> \ + Self::New {{ + ({left} at, {right}) + }} + }} ", at = x.clone().nth(i).unwrap(), left = tup(x.clone().take(i)), diff --git a/src/iterator.rs b/src/iterator.rs new file mode 100644 index 0000000..3d3dd26 --- /dev/null +++ b/src/iterator.rs @@ -0,0 +1,64 @@ +use crate::{Pick, RePick, Tupl}; +/// may add more later +pub trait IteratorOfTuples: Iterator<Item: Tupl> { + /// Map the item at: (|(x, y)| (f(x), y)) + fn map_at<const N: usize, U>( + self, + f: impl FnMut(<Self::Item as Pick<N>>::At) -> U, + ) -> impl Iterator<Item = <Self::Item as RePick<N, U>>::New> + where + Self::Item: RePick<N, U>; + /// make it just one: (|x| x.0) + fn just<const N: usize>( + self, + ) -> impl Iterator<Item = <Self::Item as Pick<N>>::At> + where + Self::Item: Pick<N>; + /// map the item to just one, then map that one: (|x| f(x.0)) + fn map_just<const N: usize, U>( + self, + f: impl FnMut(<Self::Item as Pick<N>>::At) -> U, + ) -> core::iter::Map< + impl Iterator<Item = <Self::Item as Pick<N>>::At>, + impl FnMut(<Self::Item as Pick<N>>::At) -> U, + > + where + Self: Iterator<Item: Pick<N>> + Sized, + { + self.just().map(f) + } +} +impl<I: Iterator<Item: Tupl>> IteratorOfTuples for I { + #[expect(refining_impl_trait)] + fn map_at<const N: usize, U>( + self, + mut f: impl FnMut(<Self::Item as Pick<N>>::At) -> U, + ) -> core::iter::Map< + I, + impl FnMut( + <I as Iterator>::Item, + ) -> <<I as Iterator>::Item as RePick<N, U>>::New, + > + where + Self::Item: RePick<N, U>, + { + self.map(move |x| { + let (l, at, r) = x.depict(); + let at = f(at); + Self::Item::unpick(l, at, r) + }) + } + + #[expect(refining_impl_trait)] + fn just<const N: usize>( + self, + ) -> core::iter::Map< + I, + impl FnMut(<I>::Item) -> <<I>::Item as Pick<N>>::At, + > + where + Self::Item: Pick<N>, + { + self.map(|x| x.pick()) + } +} @@ -5,7 +5,9 @@ //! //! start with [`Tupl`]. mod implementations; +mod iterator; mod picks; +pub use iterator::IteratorOfTuples; /// Reverse a tuple. pub trait Reverse: Tupl { type Reversed: Tupl; @@ -77,11 +79,20 @@ pub trait Pick<const N: usize>: Tupl { type L: Tupl; /// self[N + 1..] type R: Tupl; + /// self::L + Self::R + type Delete: Tupl; + /// without Self::At + fn delete(l: Self::L, r: Self::R) -> Self::Delete; /// reconstruct fn repick(l: Self::L, at: Self::At, r: Self::R) -> Self; /// deconstruct fn depict(self) -> (Self::L, Self::At, Self::R); } + +pub trait RePick<const N: usize, T>: Pick<N> + Sized { + type New: Tupl; + fn unpick(l: Self::L, at: T, r: Self::R) -> Self::New; +} /// Main tuple trait. #[diagnostic::on_unimplemented( label = "this is not a tuple, or it is too big a tuple (>26 elements)" |