daru
daru copied to clipboard
Transform a vector at values passing a particular condition
#where is used to list those values of vector that pass a particular condition. May be it would be equally good to have something in Daru that lets you do transformation to a vector for values that pass a particular condition.
It would work as follow:
> def convert_to_days week
> "#{week.split.first.to_i * 7} days"
> end
> dv = Daru::Vector.new ['3 days', '5 weeks', '2 weeks']
> dv2 = dv.apply_where(dv.match /weeks/) do |val|
> convert_to_week val
> end
> dv2
#<Daru::Vector:17000420 @name = nil @metadata = {} @size = 3 >
nil
0 3 days
1 35 days
2 14 days
dv.match comes from this feature request.
Nifty.