GithubHelp home page GithubHelp logo

hindog / mapk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codedx/mapk

0.0 1.0 0.0 40 KB

Scala Map-like class with higher-kind key and value types

License: Apache License 2.0

Scala 100.00%

mapk's Introduction

MapK

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.

import com.codedx.util.MapK

abstract class MyKey[T](val name: String)
case object Age extends MyKey[Int]("age")
case object Name extends MyKey[String]("name")
case object NumThings extends MyKey[Int]("numThings")

val info: MapK[MyKey, cats.Id] = MapK.empty[MyKey, cats.Id]
   .updated(Age, 21)
   .updated(Name, "Dylan")

// alternate apply syntax:
import MapK.entrySyntax._
val info = MapK(Age ~>> 21, Name ~>> "Dylan")

val age: Option[Int] = info.get(Age) // Some(21)
val name: Option[String] = info.get(Name) // Some("Dylan")
val numThings: Option[Int] = info.get(NumThings) // None

Install

In 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.

mapk's People

Contributors

dylemma avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.