Skip to main content

Module keying

Module keying 

Source
Expand description

Which types are Key, and the checks that need it. Constrained generics slice 2 (#2684; the model is the track’s Q6 in design/archive/retired-tracks.md).

Key admits a type as a value Map key or Set member (and as a distinct, groupBy or join key). It is automatic, never derived: a type is Key when it is one of:

  • String, Int, Bool, Instant, Duration, Bytes or Decimal, or a refined or opaque type over one of them;
  • Option[T] or List[T] with T Key;
  • a record, sum or enum whose every field and payload is Key, and, when it is generic, whose type arguments are Key;
  • a type parameter declared K: Key (checked separately: see super::equality::require_key_vars).

Float is not Key at any depth (NaN is not equal to itself), nor are Map and Set (an order-independent encoding is possible but nothing needs one yet), functions, Effect, Query, streams, held resources, actors and the boundary-only types.

The runtime holds a composite key under a canonical encoding (__bynkKeyEncode); Key needs no witness, so it adds no hidden argument.

The store rule (store m: Map[K, V], Cache, @indexed) keeps its own String/Int predicate: those keys persist through String(k).

Functions§

key_params
The type parameters of f declared Key: its own (inline or in where) and its receiver type’s.