News for hackers. Stuff that matters.
Re:Generalizing 'jq' and Traversal Systems using optics and ... by hjntmp on Wednesday October 07, 2020 @07:04PM (#24713851)
In javascript:

  const stf = [
      {name: "x", pets: [{type: "cat", name: "kitty"},
                       {type: "cat", name: "kitty2"}]},
      {name: "y", pets: [{type: "dog"}]},
      {name: "z", pets: [{type: "cat", name: "miau"}]},
  ];

  const myTransform = ({ pets, name: ownerName }) => pets
        .filter(({type}) => type === "cat")
        .map(({ name: catName }) => ({ ownerName, catName }))

  stf
      .map(myTransform)
      .flat()
      .forEach(({ownerName, catName}) => console.log(`Cat ${catName} to ${ownerName}`))

There are no comments on this comment yet.