mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 13:11:11 +00:00
feat: bidi for containers
This commit is contained in:
parent
0f430199ab
commit
712d4e2b73
3 changed files with 138 additions and 20 deletions
|
@ -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],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue