Set Archives - Thoughts https://blog.jstassen.com/tag/set/ A place for collecting my miscellaneous thoughts. Sat, 28 Oct 2017 04:54:19 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.7 92836340 Comparing Immutable.Set() and Immutable.OrderedSet() https://blog.jstassen.com/2017/10/comparing-immutable-set-and-immutable-orderedset/ https://blog.jstassen.com/2017/10/comparing-immutable-set-and-immutable-orderedset/#respond Sat, 28 Oct 2017 04:54:19 +0000 http://blog.jstassen.com/?p=884 When comparing Immutable.Set() and Immutable.OrderedSet() you’ll need to convert the OderedSet down to just a plain Set. Comparing Immutable.Set() and Immutable.OrderedSet() To compare equality with a Set and OrderedSet use this: mySet.equals( myOrderedSet.toSet() ) Immutable .equals() compares the left and right to decide if they are both Ordered. If one is ordered and the other is … Continue reading Comparing Immutable.Set() and Immutable.OrderedSet() →

The post Comparing Immutable.Set() and Immutable.OrderedSet() appeared first on Thoughts.

]]>
When comparing Immutable.Set() and Immutable.OrderedSet() you’ll need to convert the OderedSet down to just a plain Set.

Comparing Immutable.Set() and Immutable.OrderedSet()

To compare equality with a Set and OrderedSet use this:

mySet.equals( myOrderedSet.toSet() )

Immutable .equals() compares the left and right to decide if they are both Ordered. If one is ordered and the other is not, they are not equal. isOrdered(a) !== isOrdered(b).

My Feelings

I find this a bit odd, especially when the left is a plain Set. I feel regardless if the right is Ordered or not, it’s the contents that we’re interested in comparing. However this is the Immutable.js definition. You will need to downgraded the OrderedSet for comparison via .toSet() which does have a slight cost to it. Immutable performance is worth keeping an eye on.

The post Comparing Immutable.Set() and Immutable.OrderedSet() appeared first on Thoughts.

]]>
https://blog.jstassen.com/2017/10/comparing-immutable-set-and-immutable-orderedset/feed/ 0 884