const b = a.{ id, name, age } - Object Cherry Pick

@DenisTRUFFAUT Hi! What do you think these ideas?

Maybe this idea will be useful with this cases:

case 1: Object Cherry Pick with parameter coercion

const adults
  from  data =>  { id: 42, name: 'a', age: 21, score: { c:1, php: 3, js: 5 }, likes: ['X', 'Y'] };
  from users => users.filter(u => u.age > 18)
  from conf => conf.users
  from filter => data.{ id, name, age };
  from JSON.parse
  = rawData

case2: Object Cherry Pick with Cooperative async function

useEffect(function*() {
    const data = { id: 42, name: 'a', age: 21, score: { c:1, php: 3, js: 5 }, likes: ['X', 'Y'] };
    const info = yield data.{ id, name, age }
    setState(info.json())
})

case 3: Object Cherry Pick with Logical Assignment w/ Destructuring

let { id: 42, name: 'a', age: 21, score: { c:1, php: 3, js: 5 }, likes: ['X', 'Y']; } = object;
data.{ id, age }  ||== int; 

case 4: Object Cherry Pick with ternary-like try/catch

const data = { id: 42, name: 'a', age: 21, score: { c:1, php: 3, js: 5 }, likes: ['X', 'Y'] };
let success = try?  console.log(data.{ id, age }) : false

case 5: object Cherry Pick and Pipeline tap operator |:

const doTransfomration = data => data
  .filter(x => x != null)
  .map(x => x ** 2)
  .filter(x => x > 100)
  .console.log(data.{ id, age })

notes

  1. I would like to demonstrate interesting cases with Object Cherry Pick
  2. I would like to help the community by describing my experience with Object Cherry Pick

references