Lab42Console
Intrusive Ruby Tools for the Console Only
Applying operations to collections
By using by
we create what one could call a compaignon collection which can be transformed, at the end
we can use finders and filters on these compagnon collection to access the original data
Let us for example suppose that we have the following data
let(:data) {
(0..9).map{ |n|
OpenStruct.new(id: n, name: "name #{n}", content: (0..n).map{ |k| "data #{k}" })
}
}
Now we can filter the original data by selecting on some transformations on the compagnon collection, firstly we create a compagnon collection which contains only the names:
let(:compagnon){ data.by(:name) }
Now we can access the original for example as follows
expect(compagnon.fnd("name 1")).to eq(data[1])
We can chain by
as much as we want
let(:children_count) { data.by(:content).by(:size) }
And select on children count
expect(children_count.sel(:>, 8)).to eq(data[8..9])
Author
Copyright © 2019,20 Robert Dober mailto: robert.dober@gmail.com
LICENSE
Same as Elixir -- ;) --, which is Apache License v2.0. Please refer to LICENSE for details.
SPDX-License-Identifier: Apache-2.0