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

generalize transpose to [[]], [{}], {[]} and {{}} #158

Closed
wants to merge 1 commit into from

Conversation

Fil
Copy link
Member

@Fil Fil commented Jun 25, 2020

closes #48

  • I'm not sure if Object.keys/Object.entries are allowed yet, easy to change or polyfill.
  • This is about 3x slower in the case of a regular matrix; is it worth keeping the current code and use it if matrix.length > 0 && matrix[0].length > 0 ? (https://observablehq.com/d/dff751d1da207b30)

…, objects of arrays {[]} and objects of objects {{}}.

closes #48
@mbostock
Copy link
Member

This feels too magical (overloaded) to me. I think I’d prefer to have dedicated methods for converting from array-of-objects to object-of-arrays and vice versa.

@Fil
Copy link
Member Author

Fil commented Aug 23, 2020

I'd tend to disagree: for me iterating over Object.keys(rows) and Object.keys(row) is unifying both structures and feels "natural" (maybe because that's how I represent these things in my head).

The weird part might be length ? [] : {}; because I don't know how to distinguish [] and {} otherwise?

@mbostock
Copy link
Member

The weird part might be length ? [] : {}; because I don't know how to distinguish [] and {} otherwise?

That’s exactly it. There are a variety of other ways to test for arrays (or iterables), and it’s not clear to me that the truthy length property is what we want. My thought was that if we don’t try to handle all of these cases in one method then we can more precisely define what the behavior should be. The current documentation doesn’t really say what will happen, and I think it would be cumbersome to define it.

@Fil
Copy link
Member Author

Fil commented Aug 24, 2020

d3.permute is agnostic to [] {}, but its keys are passed explicitly
https://github.com/d3/d3-array/blob/master/src/permute.js

@Fil
Copy link
Member Author

Fil commented Sep 1, 2020

Would it be more acceptable to test for x instanceof Array instead?

In any case, whether we instantiate the row or column as a [] or a {} is a bit cosmetic, since both arrays and objects can have any type of keys (integers or strings).

Also, if these are iterables we should create an Array.from them?

@mbostock mbostock removed the feature label Apr 8, 2022
@Fil
Copy link
Member Author

Fil commented Jun 30, 2022

closing due to inactivity

@Fil Fil closed this Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

transpose(object)?
2 participants