diff --git a/crates/cross/src/compound/list/mod.rs b/crates/cross/src/compound/list/mod.rs index 2d836e0..28b5e29 100644 --- a/crates/cross/src/compound/list/mod.rs +++ b/crates/cross/src/compound/list/mod.rs @@ -1,4 +1,4 @@ -use crate::compound::peano::{Peano, P0, PNext}; +use crate::compound::peano::Peano; mod flat; // mod linked; @@ -286,10 +286,34 @@ where } } +pub struct MapTagToValueOp(T /* unused */); +impl> MapVisitor> for MapTagToValueOp { + type Output = (T, V); + fn map(&self, elem: Tagged) -> Self::Output { + (P::VALUE.into(), elem.into_inner()) + } +} + +pub trait EnumerateU32 { + type Output; + fn enumerate_u32(self) -> Self::Output; +} +impl EnumerateU32 for L +where + L: Enumerate, + L::Output: Map>, +{ + type Output = >>::Output; + fn enumerate_u32(self) -> Self::Output { + self.enumerate().map(MapTagToValueOp(0u32 /* unused */)) + } +} + #[cfg(test)] mod test { use super::*; + use crate::compound::peano::{P0, P1, P2}; struct SumVal; @@ -518,7 +542,6 @@ mod test { #[test] fn enumerate_multiple() { - use crate::compound::peano::{P1, P2}; let list = (2i32, (), 4f32).into_list(); let expected = ( Tagged::::new(2i32), @@ -527,4 +550,15 @@ mod test { ).into_list(); assert!(list.enumerate() == expected); } + + #[test] + fn enumerate_u32_multiple() { + let list = (2i32, (), 4f32).into_list(); + let expected = ( + (0u32, 2i32), + (1u32, ()), + (2u32, 4f32) + ).into_list(); + assert!(list.enumerate_u32() == expected); + } }