Skip to content

Instantly share code, notes, and snippets.

@johnynek
Last active March 13, 2019 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnynek/774a7bffeaa3c69e196c9388d3eafae9 to your computer and use it in GitHub Desktop.
Save johnynek/774a7bffeaa3c69e196c9388d3eafae9 to your computer and use it in GitHub Desktop.
A module based encoding of Map which keeps the ordering associated with the Map. Then we can talk about `mymod.Map` as a type, knowing that `mymod.ordering` is the ordering.
abstract class MapModule {
type K
def ordering: Ordering[K]
type Map[_]
def empty[V]: Map[V]
def updated[V](m: Map[V], key: K, v: V): Map[V]
def get[V](m: Map[V], key: K): Option[V]
def items[V](m: Map[V]): Stream[(K, V)]
def remove[V](m: Map[V], key: K): Map[V]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment