1 Mar 2008 02:25
Re: Iterable.partition return type
J Robert Ray wrote: > I found Iterable.partition and it is the kind of operation I find myself > needing on occasion, but I am frustrated by its return type and the choice > to return Iterables. > > In one case, I want to split an array and send one of the pieces to a > function that takes a RandomAccessSeq. > > Partition uses ArrayBuffers internally to construct the two outputs. But > because I don't want to make assumptions about the implementation, I don't > want to use asInstanceOf in my code. > > My choices to convert an Iterable into an Array are less than ideal. I > already have something that I could pass to my function if it weren't > masquerading as an Iterable. > > foo.toList.toArray > foo.copyToArray(bar, 0) > Others? > > What I ended up doing was to write my own partition utility that returns > ArrayBuffers. > > There are other functions in the Iterable class that return a narrower type, > e.g., take: Collection, so would it be wrong for partition to be declared to > return a type closer to ArrayBuffer? RandomAccessSeq[A] (and hence Array) could override partition to return (RandomAccessSeq[A], RandomAccessSeq[A])(Continue reading)
RSS Feed