Re: Re: (Idea) Customizable Iterable.mkString

Nope.  Iterators are a different abstration from collections.   However, using views you can make some pretty peformant code without the need for direct iterator manipulation.  I'd recommend looking into them.

On Fri, Dec 16, 2011 at 4:15 PM, Drew <drew [at] venarc [dot] com> wrote:
Looking into views a bit more, seems like they don't apply to
Iterators, only Iterables

On Dec 16, 1:10 pm, Drew <d [dot] [dot] [dot] [at] venarc [dot] com> wrote:
> Oh wow, that looks nice. I'm not too familiar with views. Would that
> create an extra collection?
>
> -- Drew
>
> On Dec 16, 12:20 pm, Jason Zaugg <jza [dot] [dot] [dot] [at] gmail [dot] com> wrote:
>
>
>
>
>
>
>
> > On Sat, Dec 17, 2011 at 6:17 AM, Drew <d [dot] [dot] [dot] [at] venarc [dot] com> wrote:
> > > Hi Everyone,
>
> > > I was thinking that it would be useful to be able to pass a custom
> > > function to turn elements into String to Itrable.mkString. Something
> > > to replace
>
> > > items.foldLeft("")((str, item) => {
> > >                        val toAppend = if (str.isEmpty()) {
> > >                                item.toCustomString
> > >                        } else {
> > >                                "," + item.toCustomString
> > >                        }
> > >                        str + toAppend
> > >                }
>
> > > so instead will be able to write
>
> > > items.mkString(",", _.toCustomString)
>
> > I think that this is sufficient:
>
> >   items.view.map(_.toCustomString).mkString(",")
>
> > -jason

Copyright © 2013 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland