This case revealed I am missing something in pattern matching and evaluation in case of match, or I can't grasp it due to the busy week I have. Either way, I find this problem interesting for wider audience:
asso = <|
"key" -> <|"a" -> "1", "b" -> Compress@"test"|>
|>
We want to replace the inner association with uncompressed value from "b"
key. The expected result is:
<|"key" -> "test"|>
Association
is HoldAllComplete
so we will have to use Trott-Strzebonski technique or RuleCondition
.
The problem is it works but throws a message in between:
asso /. KeyValuePattern[ {"a" -> "1", "b" -> val_String}] :> With[
{eval = Uncompress[val]}
, eval /; True
]
(*or RuleCondition@Uncompress[val]*)
Uncompress::argt: Uncompress called with 0 arguments; 1 or 2 arguments are expected. <|"key" -> "test"|>
The question is, what am I missing? Recent chat discussion confirms that is not obvious.
I have stuff to do so I'm just using the workaround:
asso /. sub : KeyValuePattern[{"a" -> "1", "b" -> _String}
] :> RuleCondition @ Uncompress @ sub @ "b"
but I don't get the difference that makes it work.
With
code does not give the uncompressed output in Open Cloud.asso /. KeyValuePattern[{"a" -> "1", "b" -> val_String}] :> RuleCondition @ Uncompress @ val
does give the uncompressed output but also issues a message. Which part of this is more interesting to you? $\endgroup$KeyValuePattern
. At the moment I'm not. So any insight is on topic. Also, as pointed out I don't see the reason why my workaround works so I'd say the open cloud kernel is closer to me ;) $\endgroup$<|0 -> 0, 1 -> 2|> /. KeyValuePattern[{a_ -> b_, c_ -> d_}] :> (1 /; {d} =!= {c})
even though the condition isTrue
. $\endgroup$