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.