MapK is a utility class that we implemented for Code Dx. It's like a scala.collection.immutable.Map[K, V], but where K and V are "higher-kinded" types like Option or List.
It's useful for when you have some "key" class that's parameterized on a type T, and you want to store a value of the appropriate type for each key, e.g.
importcom.codedx.util.MapKabstractclassMyKey[T](valname:String)
caseobjectAgeextendsMyKey[Int]("age")
caseobjectNameextendsMyKey[String]("name")
caseobjectNumThingsextendsMyKey[Int]("numThings")
valinfo:MapK[MyKey, cats.Id] =MapK.empty[MyKey, cats.Id]
.updated(Age, 21)
.updated(Name, "Dylan")
// alternate apply syntax:importMapK.entrySyntax._valinfo=MapK(Age~>>21, Name~>>"Dylan")
valage:Option[Int] = info.get(Age) // Some(21)valname:Option[String] = info.get(Name) // Some("Dylan")valnumThings:Option[Int] = info.get(NumThings) // NoneIn SBT:
libraryDependencies +="com.codedx"%%"mapk"%"1.2.0"Disregard the "packages" on the sidebar. Despite this being a public project, you still need to provide a personal access token to download the packages. Very annoying.