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

Shift<T> ergonomics #57

Open
oscbyspro opened this issue Aug 2, 2024 · 2 comments
Open

Shift<T> ergonomics #57

oscbyspro opened this issue Aug 2, 2024 · 2 comments
Labels
brrr such code, much wow

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 2, 2024

The current ergonomics of Shift<T> is terrible. I just haven't gotten around to fixing it yet.

Shift<T.Magnitude>(unchecked: Count(unchecked: index)) // ugh!
@oscbyspro oscbyspro added the brrr such code, much wow label Aug 2, 2024
@oscbyspro oscbyspro changed the title Better Shift<T> ergonomics Improved Shift<T> ergonomics Aug 2, 2024
@oscbyspro oscbyspro changed the title Improved Shift<T> ergonomics Shift<T> ergonomics Aug 2, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 23, 2024

I'll add a Shift<T>.one convenience because shifting by 1 is common:

integer.up  (Shift.one)
integer.down(Shift.one)

Note that the minimum binary integer size is 8 bits, so it is always valid. It also reads well.

oscbyspro added a commit that referenced this issue Aug 24, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Oct 27, 2024

Writing Shift<T.Magnitude> is a bit cumbersome, so I might consider a T.Shift alias:

extension BinaryInteger { public typealias Shift = CoreKit.Shift<Magnitude> }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brrr such code, much wow
Projects
None yet
Development

No branches or pull requests

1 participant