fromfrom icon indicating copy to clipboard operation
fromfrom copied to clipboard

[Questions] Working with deep nested data and arrays of parameters

Open Zireael opened this issue 5 years ago • 2 comments

Hi, Thanks for making this library - it looks promising as I'm just creating a project that could use extensive search/filter/morph of data. I'm not a pro dev, so below will be few points from that perspective

  1. I went through documentation but it's written in TS often without practical use examples. This makes it hard to figure out how am I supposed to use each transform. Would you consider providing code examples in documentation akin to how, for example, Lodash does theirs for every transformation?

  2. I've noticed your usage examples on Playground show working with flat data. If I have some objects nested few levels deep, would you expect me to manually destructure object tree and then feed each branch to fromfrom transforms? Ideally I would like to filter the entire object tree in one operation (see example mockup object https://pastebin.com/icBgpV5c), and for example if I want to do .filter(color: "green") and get as output new object with only branches that end with a color: "green" (expected: https://pastebin.com/a8qUnPp0). Could you give example of how you envision a workflow of operations when working with nested data like this? I'm most interested in .filter .sort .groupBy .find .pick

  3. How do you envision us doing operations with multiple parameters/conditions? Let's say I want to filter by two colours and have my filter parameters stored in separate array. Would doing it like this be the best way?:

const fndcolours = ["red", "green"];

from(data)
 .filter(user => fndcolours.includes(user.color))
  .toArray();

Thanks again

Zireael avatar Mar 28 '19 21:03 Zireael

To answer your third question...

You might like to reduce lookup times, and I would use a Set object.

const fndcolors = new Set<string>(["red", "green"]);

from(data)
  .filter(user => fndcolors.has(user.color))
    .toArray();

jtenner avatar Mar 29 '19 13:03 jtenner

Hi @Zireael and thank you for your questions.

  1. You're absolutely right. I would want to have code examples on each of the transformations in the documentation. This is something that is an easy way to start contributing. I created a separate issue #49 for this.

  2. Nested data is something that fromfrom is not good at handling. You might want to look for a library that is specially made for handling tree structures.

  3. Filtering with multiple conditions is not different from handling a single condition:

from(data)
  .filter(item => condition1 && condition2 && condition3)
  .toArray()

or by separating the cases:

from(data)
  .filter(item => condition1)
  .filter(item => condition2)
  .filter(item => condition3)
  .toArray()

tomi avatar May 30 '19 13:05 tomi