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

Improve BitArray's constructors #11898

Merged
merged 3 commits into from Mar 18, 2022

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Mar 14, 2022

  • Adds a block-accepting overload, similar to other containers: BitArray.new(7, &.even?) # => BitArray[1010101]
  • Allows non-Int32 size arguments, also similar to other containers. The size is converted within the constructor. The added Int restriction is not a breaking change because size was previously used to initialize an Int32 instance variable directly.
  • Raises if the size argument is negative, instead of silently returning an empty BitArray for sizes within -31..-1.

I avoided BitArray.[] because it could be interpreted in two ways, a variadic literal-like constructor (which requires changes to #inspect's format), and an integer-to-bits constructor (similar to the from_int spec helper method).

@straight-shoota
Copy link
Member

I'm not sure if the yielding overload is that useful, but it's probably good to have it for consistency.

@straight-shoota straight-shoota added this to the 1.4.0 milestone Mar 14, 2022
@straight-shoota straight-shoota merged commit cd02c11 into crystal-lang:master Mar 18, 2022
@HertzDevil HertzDevil deleted the feature/bitarray-ctor branch March 19, 2022 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants