scala - Can this be simplified? -
referring previous answer of mine on stackoverflow
the core of complexity illustrated in 1 method:
implicit def traversabletofilterops[cc[x] <: traversable[x], t] (xs: cc[t])(implicit witness: cc[t] <:< traversablelike[t,cc[t]]) = new morefilteroperations[cc[t], t](xs) with 2 questions:
is there way give compiler hint
mapmeets signaturecc[x] <: traversable[x]? expect matchtraversable[tuple2[_,_]]doesn't happen. in end, had write second method takingcc[kx,vx] <: map[kx,vx], feels redundantwitness: cc[t] <:< traversablelike[t,cc[t]]seems redundant given first type parameter, gut feeling enforced type oftraversable, must always hold true possible subclass or value ofx, there should no reason explicitly require witness.
if test using existential type in repl, compiler seems agree me:
scala> implicitly[traversable[x] <:< traversablelike[x,traversable[x]] forsome { type x }] res8: <:<[traversable[x],scala.collection.traversablelike[x,traversable[x]]] forsome { type x } = <function1> is there therefore way away boilerplate?
i'm scala noob, please don't shoot me down if doesn't help.
assuming this:
class morefilteroperations[repr <% traversablelike[t,repr], t] (xs: repr) {} would work?
// t2fo short traversabletofilterops implicit def t2fo[repr <% traversablelike[t, repr], t](xs: repr) = new morefilteroperations[repr, t](xs) // m2fo short maptofilterops implicit def m2fo[repr <% map[k, v] <% traversablelike[(k,v), repr], k, v] (xs: repr) = new morefilteroperations[repr, (k, v)](xs) this should work because (according book have.. programming scala, p264) following method definition view bound:
def m [a <% b](arglist): r = ... it same method definition:
def m [a](arglist)(implicit viewab: => b): r = ...
Comments
Post a Comment