UpdateWhere is a handy function
twitter.com
UpdateWhere is a handy function
1–10 of 32 posts
Re: UpdateWhere is a handy function
#2Is this function known by any other name?
Re: UpdateWhere is a handy function
#3Would 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
#4This 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
#5 para (\t -> let asIs = (map fst t) in if(whereFn(asIs)) updateFn(asIs) else map snd t)Re: UpdateWhere is a handy function
#6Feels 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
> 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
#7Feels 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
#8[1] https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-...
Re: UpdateWhere is a handy function
#9This 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 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.
Re: UpdateWhere is a handy function
#10Something is very wrong if you need these.
Get help. Use a hashmap. Plz