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.

The source
{
  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 },
  ],
}
The config
{
  $map: {
    over: {
      $filter: {
        over: { $ref: '$.products' },
        as: 'p',
        when: { $get: { from: { $var: 'p' }, path: ['inStock'] } },
      },
    },
    as: 'p',
    body: { $get: { from: { $var: 'p' }, path: ['name'] } },
  },
}
What comes out
['Apple', 'Carrot']
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.