diff --git a/src/__tests__/__snapshots__/indexBy-test.js.snap b/src/__tests__/__snapshots__/indexBy-test.js.snap index ee3ee41..2b433ac 100644 --- a/src/__tests__/__snapshots__/indexBy-test.js.snap +++ b/src/__tests__/__snapshots__/indexBy-test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`transmute/indexBy indexes a List 1`] = ` -Immutable.Map { +Immutable.OrderedMap { "123": Immutable.Map { "id": "123", }, @@ -23,7 +23,7 @@ Immutable.Map { `; exports[`transmute/indexBy indexes an Array 1`] = ` -Object { +Immutable.OrderedMap { "123": Immutable.Map { "id": "123", }, @@ -34,7 +34,7 @@ Object { `; exports[`transmute/indexBy indexes an Object 1`] = ` -Object { +Immutable.OrderedMap { "123": Object { "id": "123", }, diff --git a/src/indexBy.js b/src/indexBy.js index 6b72970..f146d48 100644 --- a/src/indexBy.js +++ b/src/indexBy.js @@ -1,13 +1,13 @@ -import _keyedEquivalent from './internal/_keyedEquivalent'; import _reduce from './internal/_reduce'; -import _set from './internal/_set'; import curry from './curry'; import { Iterable, Map, OrderedMap } from 'immutable'; function indexBy(keyMapper, subject) { return _reduce( - _keyedEquivalent(subject), - (acc, v, k) => _set(keyMapper(v, k, subject), v, acc), + Iterable.isOrdered(subject) || !Iterable.isIterable(subject) + ? OrderedMap() + : Map(), + (acc, v, k) => acc.set(keyMapper(v, k, subject), v), subject ); } diff --git a/src/internal/_keyedEquivalent.js b/src/internal/_keyedEquivalent.js index b95dcfd..8eea5bc 100644 --- a/src/internal/_keyedEquivalent.js +++ b/src/internal/_keyedEquivalent.js @@ -1,4 +1,4 @@ -import { Collection, Iterable, Map, Seq } from 'immutable'; +import { Collection, Map, Seq } from 'immutable'; import { keyedEquivalent } from './TransmuteCollection'; const makeObject = () => ({});