blockchainsmartcontractsonflow-cadence

Is it possible to iterate over dictionary keys?


The current method of accessing dictionary keys is through the use of the <dictionary_name>.keys field.

However, this may result in resource exhaustion for large dictionaries.

How can I iterate over the keys for the dictionary, instead of all the keys as an array?


Solution

  • Dictionaries have a fun forEachKey(_ function: ((K): Bool)): Void function.