Working with Subsets of an Immutable.js Map()

InstructorJ.S. Leonard

Share this video with your friends

Send Tweet

Immutable.js offers methods to break immutable structures into subsets much like Array--for instance it has the all powerful slice()--and unlike Array it offers functional methods like take() and skip(). You get the best of both the imperative and functional worlds.

Gleb
~ 8 years ago

I am a bit confused, but what's the case of using takeLast(4) with the map if it's unordered? It seems that we can't be sure which 4 will really be returned?

J.S. Leonardinstructor
~ 8 years ago

Hi Jan,

Good question. When I recorded these videos I believe Map() didn't have an order "guarantee" but it would stay in order nonetheless, especially for simple operations, which is why those tests pass. But you are right, there isn't a good use case for takeLast(X), so use OrderedMap when you need the guarantee (at the cost of some performance).

sfyr111
~ 6 years ago

have a error for skipWhile, which return size 7 map