Skip to content

Exists: positively safe but negatively unsafe (???) #426

@salvalcantara

Description

@salvalcantara

I would like someone to confirm whether the following behaviour is expected. Given:

{
  "a": [ 
    {"b": 1, "c": [1, 2, 3], "d": "foo"},
    {"b": 2, "d": "bar"},
    {"c": [0]}
  ]
}
  • a.exists(x, x.b == 1) returns true
  • a.exists(x, x.b == 3 ) returns this error: failed to evaluate: no such key: b

Is this asymmetry expected? It seems that exists is positively safe but negatively unsafe, which feels weird. I would expect the evaluation to fail in both cases. For what it's worth, that is indeed what happens with filter. You can check the example online here.

At first I thought that in the affirmative case the computation was being short-circuited after evaluating the first (matching) element but that is not the case. You can confirm by rearranging the array; the order does not matter.

Originally posted here:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions