Created
December 5, 2014 16:03
-
-
Save AlecZorab/b6a71d6ed9d6df97cbc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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