Prism · Composition
Filter, then map
Operators nest: what one gives is what the next takes. Here the list is filtered first, and what is left is mapped.
{
products: [
{ name: 'Apple', price: 1.5, inStock: true },
{ name: 'Banana', price: 0.5, inStock: false },
{ name: 'Carrot', price: 2, inStock: true },
{ name: 'Date', price: 3, inStock: false },
],
}{
$map: {
over: {
$filter: {
over: { $ref: '$.products' },
as: 'p',
when: { $get: { from: { $var: 'p' }, path: ['inStock'] } },
},
},
as: 'p',
body: { $get: { from: { $var: 'p' }, path: ['name'] } },
},
}['Apple', 'Carrot']
Runs in this page on the installed package. The input and the expected output are defined by the example.