DrBoolean / immutable-ext

fantasyland extensions for immutablejs
ISC License
490 stars 20 forks source link

The argument roles in `concat` are not commutative? #7

Closed dmitriz closed 7 years ago

dmitriz commented 7 years ago

Adding extra: false to the first concat argument generates type error, even when the same key is present on the second argument:

      Map({name: "brian", age: Sum(30), extra: false})
        .concat(
          Map({name: "lonsdorf", age: Sum(30), extra: true})
        ),
      Map({name: "brianlonsdorf", age: Sum(60), extra: true}))

generates

  1) Maps concats the vals:
     TypeError: prev.concat is not a function
      at mergeWith (index.js:53:46)
      at node_modules/immutable/dist/immutable.js:1956:52
      at updateInDeepMap (node_modules/immutable/dist/immutable.js:1973:22)
      at updateInDeepMap (node_modules/immutable/dist/immutable.js:1982:23)
      at Map.updateIn (node_modules/immutable/dist/immutable.js:1280:26)
      at Map.update (node_modules/immutable/dist/immutable.js:1272:14)
      at node_modules/immutable/dist/immutable.js:1955:22
      at node_modules/immutable/dist/immutable.js:1379:16
      at ArrayMapNode.iterate.HashCollisionNode.iterate [as iterate] (node_modules/immutable/dist/immutable.js:1728:11)
      at Map.__iterate (node_modules/immutable/dist/immutable.js:1377:32)
      at Map.forEach (node_modules/immutable/dist/immutable.js:4383:19)
      at node_modules/immutable/dist/immutable.js:1963:19
      at Map.withMutations (node_modules/immutable/dist/immutable.js:1355:7)
      at mergeIntoCollectionWith (node_modules/immutable/dist/immutable.js:1952:23)
      at mergeIntoMapWith (node_modules/immutable/dist/immutable.js:1925:12)
      at Map.mergeWith (node_modules/immutable/dist/immutable.js:1310:14)
      at Map.concat (index.js:53:15)
      at Context.it (test/test.js:24:10)
DrBoolean commented 7 years ago

Map is only concattable if every value inside is. Otherwise, it'd just be merge.

Should be extra: All(true) or extra: Any(true) where All and Any are semigroups