Skip to content

Conversation

@kgullion
Copy link
Contributor

@kgullion kgullion commented Oct 26, 2024

Adds new patterns to the tarr! macro to support elixir-style matching

Handy for "recursively" iterating on a TypeArray.

eg

pub trait IndexOf<V> {
    type Idx: Unsigned;
    type Found: Bit;
}
impl<V> IndexOf<V> for tarr![] {
    type Idx = U0; // Always zero if not found
    type Found = B0;
}
impl<V, HD, TL: IndexOf<V>> IndexOf<V> for tarr![HD | TL]
where
    V: IsEqual<HD, Output: BitOr<TL::Found, Output: Bit>>,
    TL::Idx: Add<TL::Found, Output: Unsigned>,
{
    type Idx = Sum<TL::Idx, TL::Found>; // Add one if V in TL
    type Found = Or<Eq<V, HD>, TL::Found>;
}

btw, I've been using this lib (mostly TArr and Unsigned) pretty heavily. might put together a PR for some more of my utils in the future but link for the curious.

@paholg paholg merged commit 68980e9 into paholg:main Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants