Live data from Hacker News

UpdateWhere is a handy function

twitter.com

1–10 of 32 posts

Re: UpdateWhere is a handy function

#2
This is a simple function that I find quite useful. Crawl through an object to update some specific nested value. Useful for things like optimistic updates in a cache (eg. Find every instance of an object with some guid in any random data structure and update a field in it).

Is this function known by any other name?

Re: UpdateWhere is a handy function

#3
Feels like something had gone very wrong if a function like this is useful.

Would only be useful for unstructured data since if you had structure data you could write a more specific function.

This can easily match the wrong value and cause problems. And why would it match the wrong value? Because you have unstructured data and it might not be knowable if you might have false positives

Re: UpdateWhere is a handy function

#4

This is a simple function that I find quite useful. Crawl through an object to update some specific nested value. Useful for things like optimistic updates in a cache (eg. Find every instance of an object with some guid in any random data structure and update a field in it). Is this function known by any other name?

Disliking the generality of this function (as a sibling commenter said.. I mean with the wrong predicate you won't even get to test for list or dict.. but ok for those nested list/dict structures; but why not test first for them?) it is just a map and an if, or a map/list comprehension?

Re: UpdateWhere is a handy function

#6

Feels like something had gone very wrong if a function like this is useful. Would only be useful for unstructured data since if you had structure data you could write a more specific function. This can easily match the wrong value and cause problems. And why would it match the wrong value? Because you have unstructured data and it might not be knowable if you might have false positives

This is often useful if you're rewriting something that looks like an abstract syntax tree.

> And why would it match the wrong value?

Because you may be searching the tree for something that looks like `(op(const)(const))` to replace it with `(const)`. But that may live many levels deep inside the structure.

Also, from existing names, that seems very close to MapIf (https://resources.wolframcloud.com/FunctionRepository/resour...) just with added recursion.

Re: UpdateWhere is a handy function

#7

Feels like something had gone very wrong if a function like this is useful. Would only be useful for unstructured data since if you had structure data you could write a more specific function. This can easily match the wrong value and cause problems. And why would it match the wrong value? Because you have unstructured data and it might not be knowable if you might have false positives

I disagree. For example, It's useful if you have a bunch of cached network requests that each list some resources and you want to update all of the instances of a specific resource (matching by uuid).

Re: UpdateWhere is a handy function

#9

This is a simple function that I find quite useful. Crawl through an object to update some specific nested value. Useful for things like optimistic updates in a cache (eg. Find every instance of an object with some guid in any random data structure and update a field in it). Is this function known by any other name?

I mean, the paradigm would be a iterable-based dispatch. There's no name (that I know of) for such a specific (and yet, weirdly general) implementation.

I agree with many others in this thread when it comes to this being too specific to be useful and too generic to keep you from shooting yourself in the foot. I would, instead, add this to Array/Object's prototypes and call it on the specific types instead. At least, in that case, you aren't handling multiple fields of concern.

Post reply on HN