Skip to content

Instantly share code, notes, and snippets.

@AlecZorab
Created December 5, 2014 16:03
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 AlecZorab/b6a71d6ed9d6df97cbc7 to your computer and use it in GitHub Desktop.
Save AlecZorab/b6a71d6ed9d6df97cbc7 to your computer and use it in GitHub Desktop.
class MapBool[K, V](implicit ev: Bool[V]) extends Bool[Map[K, V]] with Serializable {
def one = Map.empty[K, V].withDefaultValue(ev.one)
def or(a: Map[K, V], b: Map[K, V]) = {
val ad = a.withDefaultValue(ev.zero)
val bd = b.withDefaultValue(ev.zero)
(a.keySet ++ b.keySet).map(k => k -> ev.or(ad(k), bd(k))).toMap
}
def complement(a: Map[K, V]) = a.mapValues(ev.complement)
def and(a: Map[K, V], b: Map[K, V]) =
(a.keySet intersect b.keySet).map(k => k -> ev.and(a(k), b(k))).toMap
def zero = Map.empty[K, V].withDefaultValue(ev.zero)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment