Transform/traverse Shapeless' HMap

Viewed 99

Shapeless' HListOps includes a number of useful functions for their heterogeneous HList type. I couldn't find an equivalent for HMap.

Here is my goal. I have a simple Map[String, String] which is used as an options repository in the pipeline of message processing in quite a few places of my application. I now would like to add a different (Key => Value) to this map, by transforming it to a HMap, so it could be something like:

class HOptionsMap[K, V]
implicit val intToString = new HOptionsMap[String, String]
implicit val stringToInt = new HOptionsMap[String, Instant]

So I could further use it as follows:

val hm = HMap[HOptionsMap]("placeOfIncident" -> "Toronto", "incidentDate" -> Instant.now)

Except I would like to call operations like collect, fold, filter on the above, which are not supported (unlike with HList). This is a requirement in order to not break current functionality.

Of course I could use composition here but I would be curious if this would be achievable with Shapeless library.

1 Answers
Related