Skip to content

Commit

Permalink
contravariance solved
Browse files Browse the repository at this point in the history
  • Loading branch information
wheaties committed Dec 23, 2013
1 parent d0186ce commit 4eb8039
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/main/scala/com/wheaties/choice/Choice.scala
Expand Up @@ -8,16 +8,17 @@ trait Choice[-Value]{

protected[choice] def filter[V <: Value]: Predicate1[V]

def get[C](collection: C)(implicit view: View[Value,C]) = view(collection, filter)
def get[C, V <: Value](collection: C)(implicit view: View[V,C]) = view(collection, filter)

def set[A,C](collection: C, value: A)(implicit replace: Replace[Value,C,A]) = replace(collection, value, filter)
def set[A,C, V <: Value](collection: C, value: A)(implicit replace: Replace[V,C,A]) =
replace(collection, value, filter)

def mod[C](collection: C, f: Value => Value)(implicit modify: Modify[Value,C]) = modify(collection, f, filter)
def mod[C, V <: Value](collection: C, f: V => V)(implicit modify: Modify[V,C]) = modify(collection, f, filter)

def compose[V <: Value](that: Choice[V]) = that andThen this

def andThen[V <: Value](that: Choice[V]) = new Choice[V]{
protected[choice] def filter[V <: Value] = (self.filter) and (that.filter)
protected[choice] def filter[VV <: V] = (self.filter) and (that.filter)
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/scala/com/wheaties/choice/Choose.scala
Expand Up @@ -35,10 +35,6 @@ object Choose{
}
}

def apply[V](pred: Predicate1[V]) = new Choose[V]{
protected[choice] def filter[VV <: V] = pred
}

implicit def neg[V] = new Negation[Choose[V]] {
def not(that: Choose[V]) = new Choose[V] {
protected[choice] def filter[VV <: V] = Not(that.filter)
Expand Down
4 changes: 0 additions & 4 deletions src/main/scala/com/wheaties/choice/Ignore.scala
Expand Up @@ -36,10 +36,6 @@ object Ignore{
}
}

def apply[V](pred: Predicate1[V]) = new Ignore[V]{
protected[choice] def scheme[VV <: V] = pred
}

implicit def neg[V] = new Negation[Ignore[V]] {
def not(that: Ignore[V]) = new Ignore[V] {
protected[choice] def scheme[VV <: V] = Not(that.scheme)
Expand Down

0 comments on commit 4eb8039

Please sign in to comment.