Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zireael opened this issue Mar 28, 2019 · 2 comments
Open

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

Zireael opened this issue Mar 28, 2019 · 2 comments

Comments

@Zireael
Copy link

Zireael commented Mar 28, 2019

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

@jtenner
Copy link
Contributor

jtenner commented Mar 29, 2019

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();

@tomi
Copy link
Owner

tomi commented May 30, 2019

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 Doc: Add usage example for sequence methods #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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants