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:

  1. is there way give compiler hint map meets signature cc[x] <: traversable[x]? expect match traversable[tuple2[_,_]] doesn't happen. in end, had write second method taking cc[kx,vx] <: map[kx,vx], feels redundant

  2. witness: cc[t] <:< traversablelike[t,cc[t]] seems redundant given first type parameter, gut feeling enforced type of traversable , must always hold true possible subclass or value of x, 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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -