immer
immer copied to clipboard
Add iterator version for map::find()
I've got code working for this, but I'm struggling to come up with a name for the iterator based method. Any suggestions ?
Would you like me to look at the code? Maybe find()
is ok. Or lookup()
. Or we can rename the current one as lookup()
. Note that the current version, I believe, covers most cases of find()
with lower overhead.
Sorry for the delay getting back to you, it took a bit longer than I thought to get approval from work to share the patch.
https://github.com/basicer/immer/commit/0dcde00eaea6e03909eed4c33c81705798181898
I agree the current version is better for most use-cases. The situation I was running up against is an API where I return some pairs in the map to the caller, limited to some number. The caller can then make another request for the next page by providing the last key they saw. Without this, I either had to make a side lookup table of page ending keys to iterators, or reiterate the entire map to get back to the beginning of the next page.
Thanks @basicer! Maybe I will add a version of this based on that at some point. I'm not so sure about the usefulness of beginOrAfter()
, whats your use-case for that?
Also, yous aid you needed approval, are you using Immer at your work at Roblox? :smiley:
We are considering it!
The use case for beginAtOrAfter() is that if the key your looking for is from an old version of the map, you can still iterate. It doesn't exactly work though, because if the key you provide that doesn't exist happens to be in between two entries on the collision list, there's no way to know where that key would have been in the collision list.
Ah, interesting... good luck in your experiments with it, I hope it ends up being useful!