feat: bidi for containers

This commit is contained in:
Shunsuke Shibayama 2023-09-05 17:21:59 +09:00
parent 0f430199ab
commit 712d4e2b73
3 changed files with 138 additions and 20 deletions

View file

@ -1267,3 +1267,26 @@ pub trait StructuralEq {
pub trait __Str__ {
fn __str__(&self) -> String;
}
pub trait OptionalTranspose {
type Output;
type Fill;
/// `self: Option<_>`
fn transpose(self, fill: Self::Fill) -> Self::Output
where
Self: Sized;
}
impl<T: Clone> OptionalTranspose for Option<Vec<T>> {
type Output = Vec<Option<T>>;
type Fill = usize;
fn transpose(self, fill: Self::Fill) -> Self::Output
where
Self: Sized,
{
match self {
Some(v) => v.into_iter().map(Some).collect(),
None => vec![None; fill],
}
}
}