Skip to content

How to check if key exists in map (for a map with many items) #1626

Answered by eonpatapon
Roohiya asked this question in General
Discussion options

You must be logged in to vote

What may cause a performance issue is that you are generating a big disjunction with or, more than the for comprehension itself.

A possibility would be to define another field which does some kind of assertion:

items: {
     "item1": 1
     "item2": 2
}

item: string
itemExists: true & items[item] != _|_

item: "item1"
// item: "item3" // will fail

https://cuelang.org/play/?id=SI8GGu0F3WI#cue@export@cue

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Roohiya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants