How to case match a View in scala -


i'm implementing class constrain access on iterable. intermediate steps of sequence (after map, etc...) expected big memory. map (and likes: scanleft, reduce, ...) should lazy.

internally use map(...) = iterable.view.map( ... ). seems, iterableview.view not it-self, produce useless redirection when calling map multiple times. not critical, i'd call .view if iterable not view.

so, how can case-match view?

class lazyiterable[a](iterable: iterable[a]){    def map[b](f: => b) = {     val mapped = iterable match {       case v: view[a] => v              // should here?       case i: iterable[a] => i.view     }.map( f ))      new lazyiterable(mapped)   }    def compute() =  iterable.tolist  } 

note don't know inputed iterable, concrete seq (e.g. list, vector) or view. , if view, don't know on concrete seq type (e.g. interableview, seqview, ...). , got lost in class hierarchy of view's & viewlike's.

v: iterableview[a,_] looking ...

but don't think need of begin with.

i don't see having wrapper buys @ all. benefits writing

new lazyiterable(mything).map(myfunc).compute 

have on

mything.view.map(myfunc).tolist 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -