Skip to content
Playground(another site)

bynk.types.not_keyable

Error A Map key, Set element, or distinct/distinctBy/groupBy/join key, or an argument to a Key-bounded parameter, is not Key. String, Int, Bool, Instant, Duration, Bytes, Option/List of a key type, refined and opaque types over them, and records, sums and enums made only of key types are; a Float is never one, at any depth, because NaN is not equal to itself (constrained-generics slice 2).

A Map key, a Set element, or the key of a distinct, distinctBy, groupBy or join, must be a Key type, one whose equal values can always be found again. String, Int, Bool, Instant, Duration, Bytes and Decimal are, as are Option and List of a key and records, sums and enums made only of keys. A Float never is, at any depth, because NaN is not equal to itself, so a key holding one could never be looked up. Key on a type that is: an Int count of cents, say, or a String.

Example

fn distinctPrices(xs: List[Float]) -> Int {
let seen: Set[Float] = Set.of(xs) // ✗ `Float` is not a `Key`
seen.length()
}
fn distinctPrices(xs: List[Int]) -> Int {
let seen: Set[Int] = Set.of(xs) // ✓ `Int` is
seen.length()
}

In the Book

See also