
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Piecewise Enumerables, Enumerators, and Lazy Enumerators for Ruby.
Do you ever find yourself doing something like:
even_keys = tuples.map { |k, v| k.upcase if v.even? }.compact
Or:
even_keys = tuples.select { |_, v| v.even? }.keys.map(&:upcase)
I've always found this pattern a little bit off-putting, especially when I have
a big do
..end
block containing conditional logic and then a .compact
tacked on to it. (Maybe I'm picky.) And sometimes nil
is a valid value, so
you have to introduce a new sentinel value to reject by. You can wrap the logic
in an Enumerator.new { |yielder| .. }
or move the logic to a method that
returns an enumerator, but that can be a lot of boilerplate for a simple
filter+map operation.
This simple gem monkeypatches Enumerable, Enumerator, and Enumerator::Lazy to
add a #piecewise
method that lets you do kind of an inline enumerator. The
above example can be rewritten like this:
even_keys = tuples.piecewise { |yielder, (k, v)| yielder << k.upcase if v.even? }
I find this easier to read and grok. Perhaps you will too.
Add this line to your application's Gemfile:
gem 'piecewise'
And then execute:
$ bundle
Or install it yourself as:
$ gem install piecewise
After checking out the repo, run bin/setup
to install dependencies. Then, run
rake test
to run the tests. You can also run bin/console
for an interactive
prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To
release a new version, update the version number in version.rb
, and then run
bundle exec rake release
, which will create a git tag for the version, push
git commits and tags, and push the .gem
file to
rubygems.org.
This gem was briefly named chainenum before being renamed to piecewise.
Bug reports and pull requests are welcome on GitHub at https://github.com/mwpastore/ruby-piecewise.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that piecewise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.