Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add elixir-style tarr![A, B, C | Rest] (where Rest: TypeArray) capturing of the rest of the array #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kgullion
Copy link

@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.

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.

1 participant