The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Working with Subsets of an Immutable.js Map()

Working with Subsets of an Immutable.js Map()

7:43
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.
Watch this lesson now
Avatar
egghead.io

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.

Avatar
Noah

why is it called skipWhile and not takeWhile?

In reply to egghead.io
Avatar
J.S.

You are correct, it should have been takeWhile() with a predicate of todo.text != "monkey". Nice catch. That skipWhile() just so happened to satisfy the test as well since it will return everything after the first false.

In reply to Noah
Avatar
Gleb

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?

Avatar
J.S.

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).

In reply to Gleb
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?