On Thu, Jul 19, 2012 at 1:48 PM, Lachlan O'Dea <
lo...@me.com> wrote:
> Iterable docs for ++ say "Returns a new immutable iterable collection
> containing the elements from the left hand operand followed by the elements
> from the right hand operand." But it is trivial to show that is not actually
> true for all Iterables:
>
> scala> val s1: Iterable[Int] = Set(1,2,3)
> s1: scala.collection.immutable.Iterable[Int] = Set(1, 2, 3)
>
> scala> val s2: Iterable[Int] = Set(2,4)
> s2: scala.collection.immutable.Iterable[Int] = Set(2, 4)
>
> scala> s1 ++ s2
> res13: scala.collection.immutable.Iterable[Int] = Set(1, 2, 3, 4)
Lachlan, thanks for your comments.
I think "contains" has to be interpreted in the context of Sets here,
and so ++ has honored its documented behaviour in that aspect. But WRT
the LHS "followed by" the RHS, that's kind of an undefined concept for
Iterables generally, so the docs are a bit slippery there.
>
> If the standard is that we're happy with an Iterable.++ with such
> differences in behavior, I can see no reason not to also have an Iterable.+
> to "add a single element... somewhere... maybe". Set already has +, and for
> List it would be prepend.
Yeah, + makes sense. It doesn't imply an append vs prepend , just that
the result includes the new element somewhere. Seqs could interpret +
in whatever way was most convenient: eg prepend for linked lists,
append for array buffers.
-Ben