Skip to content

Instantly share code, notes, and snippets.

@ib84
Last active December 16, 2015 11:09
Show Gist options
  • Save ib84/5425287 to your computer and use it in GitHub Desktop.
Save ib84/5425287 to your computer and use it in GitHub Desktop.
validationsHOF&Underscores
def findX(name:String, keys: (HGSortIndex[K,V], K) => HGSearchResult[V], disc:(Ordering[K],K,K) => Boolean) :
(name, (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b :HGSearchResult[V]= keys(index, key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => disc(ordering, pair._1,
key)).map(_._1).toSet
b.forall(key => c.contains(key))
}
}
assert(allTrue, "findGTE failed")
allTrue
})
val validatations : Seq[(String, (S,Seq[(K,Seq[V])]) => Try[Boolean])]=
Seq
(
findX("def findGTE(key: K)",_.findLTE(_),_.lteq(_,_)),
findX("def findGTE(key: K)",_.findLT(_),_.lt(_,_)),
findX("def findGTE(key: K)",_.findGT(_),_.gt(_,_)),
findX("def findGTE(key: K)",_.findGTE(_),_.gteq(_,_))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment