Skip to content

Commit c7f9f69

Browse files
committed
reindex iterables
1 parent daeb7d4 commit c7f9f69

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/options.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ export function valueof(data, value, type) {
1717
? map(data, constant(value), type)
1818
: typeof value?.transform === "function"
1919
? maybeTypedArrayify(value.transform(data), type)
20-
: value && data?.reindex
21-
? maybeTypedMap(data.reindex, (i) => value[i], type)
22-
: maybeTypedArrayify(value, type);
20+
: maybeTake(maybeTypedArrayify(value, type), data?.reindex);
21+
}
22+
23+
function maybeTake(values, index) {
24+
return index ? take(values, index) : values;
2325
}
2426

2527
function maybeTypedMap(data, f, type) {
@@ -172,6 +174,7 @@ export function isScaleOptions(option) {
172174

173175
// Disambiguates an options object (e.g., {y: "x2"}) from a channel value
174176
// definition expressed as a channel transform (e.g., {transform: …}).
177+
// TODO Check typeof option[Symbol.iterator] !== "function"?
175178
export function isOptions(option) {
176179
return isObject(option) && typeof option.transform !== "function";
177180
}
@@ -225,7 +228,7 @@ export function where(data, test) {
225228

226229
// Returns an array [values[index[0]], values[index[1]], …].
227230
export function take(values, index) {
228-
return map(index, (i) => values[i]);
231+
return map(index, (i) => values[i], values.constructor);
229232
}
230233

231234
// If f does not take exactly one argument, wraps it in a function that uses take.

0 commit comments

Comments
 (0)