User Equality Semantics for Immutable.js Data Structures

I would like Sanctuary to provide a Fantasy Land- compatible map and set types with values ​​based on equality semantics. Ideally, these values ​​would be immutable, although this is not critical, since the Sanctuary will provide pure functions for merging and managing these values.

I would like to use the good work done by the Immutable.js team; I assume that implementing robust data structures requires considerable effort!

The API provided by Immutable.js doesn't really matter, since Sanctuary will expose functions to interact with these values. However, the semantics of the equality of these types is crucial.

This is not acceptable for my use:

> Map([[[1, 2, 3], 'foo'], [[1, 2, 3], 'bar']]) Map { [1,2,3]: "foo", [1,2,3]: "bar" } 

[1, 2, 3] is the same meaning as [1, 2, 3] . You cannot have two card entries with the same key.

Processing -0 also problematic:

 > Immutable.is(Map([[0, 0]]), Map([[-0, -0]])) true 

I understand that you can define the semantics of equality of one of your own type by defining equals methods, but I want to redefine the semantics of equality of native types, such as Array and Number. Is it possible? The corresponding file looks like is.js , but I do not see the hooks for the settings.

It is possible that the map type of the Sanctuary Map may wrap the map type of Immutable.js. This will provide:

  • processing method -0 ;
  • the ability to perform value-based equality checks before performing the assoc operation, which usually results in duplicate key; and
  • a place to define various fantasy-land/ methods.

May be:

 Map kv = { negativeZero :: Maybe v , value :: ImmutableMap kv , fantasy-land/equals :: Map kv ~> Map kv -> Boolean , fantasy-land/map :: Map kv ~> (k -> a) -> Map av , fantasy-land/bimap :: Map kv ~> (k -> a, v -> b) -> Map ab , ... } 

I would like to make sure that there is no other way to achieve the desired semantics of equality before creating wrappers like the one above. facebook / immutable-js # 519 does not promise.

+7
javascript functional-programming sanctuary
source share

No one has answered this question yet.

See similar questions:

7
How to compare two objects and get key-value pairs of their differences?
0
typescript: general restrictions cause type inference to select the wrong candidate?
-3
Reducing / grouping an array in Javascript

or similar:

5670
Which operator is equal (== vs ===) should be used in comparing JavaScript?
1690
How does data binding work in AngularJS?
1567
Convert form data to javascript object using jQuery
746
What is the correct way to check string equality in JavaScript?
586
How to define equality for two JavaScript objects?
485
JQuery selectors for custom data attributes using HTML5
2
equality testing when mutable exists inside immutable.js structure
one
Immutable.js structure (updating a nested map)?
one
Immutable.js reference equality
one
Are the functions of the data structure Immutable.js?