New Functions
Closed this issue · 5 comments
- forEach((value, index, bitset) => foo)
Any timeline at this point for forEach
method?
The mapping from bit operations to set operations (difference, union, intersection, complement) would be nice as well.
Alternatively, if we implement it would you consider reviewing the pull request?
Of course would I review the PR. I have no timeline for an forEach
implementation yet, so if you would implement it - you are more than welcome. Please add tests and a note in the readme file.
I was wondering, how forEach
should behave in the following two cases:
-
"...000000001010101010": Endless leading zeros (usual case): Does the loop then stop with the last set bit?
-
"...11111111101001001010": Endless leading ones: What is the stop criteria, if endless leading ones are present?
Robert
Rather than implementing foreach (or as well as) maybe bitsets could be iterable. Then people could use for of
loops.
The iterable would not have to have an end either.
Thanks Harry, that's a nice idea. Problem is that it is recommended to provide ES5 modules for "a couple more years". When you look at the history of all of my modules, I removed ES6 features again, since babel fails to compile them, when other users try to embed those libraries. The question also remains when to stop the iteration.
I just published a new version with an iterable interface, which does not end for a negated bitset and prints all bits up the the MSB for a limited amount of bits. The not minified version uses Symbol.iterator
and is thus not backwards compatible. The minified version adds a polyfill.
Implementing forEach
is therefore not needed anymore. The only way a forEach
could break is using exceptions, so I think we have a much cleaner solution now :)