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
Post a Comment