Skip to content

HMap.get does not support subtypes of keys #810

@ashleymercer

Description

@ashleymercer

Regular Map.get allows using subtypes:

val v = Map(Option("foo") -> "bar", Option(23) -> 13)
val b = v.get(Some("foo"))  // "bar"

but the same isn't true of HMap, because it can't resolve the implicits necessary to prove that the value type is correct:

val v = HMap[(Option ~?> Id)#λ](Option("foo") -> "bar", Option(23) -> 13)
val b = v.get(Some("foo"))

// [error] could not find implicit value for parameter ev: Option ~?> shapeless.Id#λ[Some[String],V]
// [error] val b = v.get(Some("foo"))
// [error]                      ^

Would it be possible / sensible to make ~?>.λ variant in K, or would that cause other problems?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions