This Query fail, due to divide by zero error message...
<|"a" -> 1, "b" -> 0|> // Query[#a/#b &]
Missing["Failed"]
...can be prevented by wrapping Quiet
around the division:
<|"a" -> 1, "b" -> 0|> // Query[Quiet[#a/#b] &]
ComplexInfinity
But will not work if wrapped outside Query.
Is there a way to wrap Quiet
around operators - eg it's handy to Apply[...]
some operation around a list:
<|"a" -> 1, "b" -> 0, "c" -> 2|> //
Query[{{"a", "c"}, "c"} /* Apply[Divide]]
<|a->1/2,c->1|>
But
<|"a" -> 1, "b" -> 0, "c" -> 2|> //
Query[{{"a", "c"}, "b"} /* Apply[Divide]]
Missing["Failed"]
Of course if the operator is deprecated to a function, Quiet
can be used, but that's not the point here:
<|"a" -> 1, "b" -> 0, "c" -> 2|> //
Query[{{"a", "c"}, "b"} /* Apply[Quiet[Divide[##]] &]]
<|"a" -> ComplexInfinity, "c" -> ComplexInfinity|>