Re: Sorted structures lose their ordering when mapped

Oliver Ruebenacker <[email protected]> Tue, 29 Nov 2016 10:16:07 -0500
Newsgroups gmane.comp.lang.scala
Message-ID <CAA=X4OByTroWYMA8Drt84Rm2QrpxWmZACPQjHCmp8gwiu6CgLA@mail.gmail.com>
--001a114a886850385005427211bc
Content-Type: text/plain; charset=UTF-8

     Hello,

  The original ordering can only be kept if the new collection has the same
type of elements. That means your suggestion would split mapping into two
cases - same type or not same type - with different behaviors for each
case. That would certainly complicate things.

  For example, what happens when we don't know whether the type is the same
due to type parameters? Would we treat them as different?

     Best, Oliver





On Tue, Nov 29, 2016 at 1:23 AM, Tobin Yehle <[email protected]> wrote:

> On the immutable side, I think the only concrete collections that inherit
> from SortedSet are TreeSet and BitSet. I think the problem also exists in
> TreeMap, and all the mutable versions of these three structures. Mutable
> BitSets are probably the largest use case.
>
> Use cases for TreeSet and TreeMap are for situations where a HashSet/Map
> would be good, but in-order traversals are also needed. They provide Log
> insertions/deletions/lookups.
>
> My thought is that sorted collections should retain their ordering
> whenever possible.
>
> scala> val set = SortedSet(1,2,3)(ord=Ordering.Int.reverse)
> set: scala.collection.SortedSet[Int] = TreeSet(3, 2, 1)
>
> scala> set.map(identity)
> res0: scala.collection.SortedSet[Int] = TreeSet(1, 2, 3)          should
> be TreeSet(3, 2, 1)?
>
> scala> set.map(_*2)
> res1: scala.collection.SortedSet[Int] = TreeSet(2, 4, 6)         should
> be TreeSet(6, 4, 2)?
>
> and if possible
>
> scala> set.map(_*2)(collection.breakOut) : BitSet
> res2: scala.collection.BitSet = BitSet(2, 4, 6)
>  should be BitSet(6, 4, 2)?
>
> an impossible case is when the type of the objects in the container changes
>
> scala> set.map("a" * _)
> res3: scala.collection.SortedSet[String] = TreeSet(a, aa, aaa)
>  this seems like correct behavior
>
>
> On Mon, Nov 28, 2016 at 10:34 PM Vlad Patryshev <[email protected]>
> wrote:
>
>> It was a pretty nice (counter-)example, but I wonder what is "SortedSet"?
>> And of course the next question will be - how should map be defined on
>> "SortedSet"?
>>
>> It's not a joke, it's a serious question.
>>
>> Thanks,
>> -Vlad
>>
>> On Mon, Nov 28, 2016 at 8:14 PM, Tobin Yehle <[email protected]>
>> wrote:
>>
>> Not sure if I'm really posting this in the right place, but:
>>
>> Calling map on a collection that requires an implicit ordering results in
>> some surprising behavior. For example:
>>
>> scala> val set = SortedSet(1,2,3)(ord=Ordering.Int.reverse)
>> set: scala.collection.SortedSet[Int] = TreeSet(3, 2, 1)
>>
>>
>> scala> set.firstKey == set.map(identity).firstKey
>> res0: Boolean = false
>>
>> My feeling is that mapping the identity function over any collection
>> should not change anything.
>>
>> In this case it is clear what is happening. The CanBuildFrom provided by
>> SortedSet is pulling an Ordering instance out of predef (Ordering.Int)
>> instead of using the ordering from the origin collection.
>> scala> set.toList
>> res1: List[Int] = List(3, 2, 1)
>>
>>
>> scala> set.map(identity).toList
>> res2: List[Int] = List(1, 2, 3)
>>
>> scala> set.ordering
>> res3: Ordering[Int] = scala.math.Ordering$$anon$4@3ff3275b
>>
>> scala> set.map(identity).ordering
>> res4: Ordering[Int] = scala.math.Ordering$Int$@7fa85a55
>>
>> I think this can be fixed by providing a more specific CanBuildFrom
>> instance to be used when mapping between two sorted collections that
>> contain the same type.
>>
>> i.e. Provide a CanBuildFrom[Sorted[K, _], K, Sorted[K, _]] somewhere that
>> has precedence over the more generic usual CanBuildFrom[CC[_], A, CC[A]]
>>
>> I'm not sure how it could be done, but the static overloading resolution
>> rules make this possible, I think.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "scala-language" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>>
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "scala-language" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/
>> topic/scala-language/Q5A1TTEZN4Q/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal
<http://www.type2diabetesgenetics.org/>, Broad Institute
<http://www.broadinstitute.org/>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

--001a114a886850385005427211bc
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><br></div>=C2=A0=C2=A0=C2=A0=C2=A0 Hel=
lo,<br><br></div>=C2=A0 The original ordering can only be kept if the new c=
ollection has the same type of elements. That means your suggestion would s=
plit mapping into two cases - same type or not same type - with different b=
ehaviors for each case. That would certainly complicate things.<br><br></di=
v>=C2=A0 For example, what happens when we don&#39;t know whether the type =
is the same due to type parameters? Would we treat them as different?<br><b=
r></div><div>=C2=A0=C2=A0=C2=A0=C2=A0 Best, Oliver<br></div><div><br><br></=
div><div><br>=C2=A0 <br></div></div><div class=3D"gmail_extra"><br><div cla=
ss=3D"gmail_quote">On Tue, Nov 29, 2016 at 1:23 AM, Tobin Yehle <span dir=
=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">tobi=
[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote"=
 style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr">On the immutable side, I think the only concrete collections=
 that inherit from SortedSet are TreeSet and BitSet. I think the problem al=
so exists in TreeMap, and all the mutable versions of these three structure=
s. Mutable BitSets are probably the largest use case.<div><br></div><div>Us=
e cases for TreeSet and TreeMap are for situations where a HashSet/Map woul=
d be good, but in-order traversals are also needed. They provide Log insert=
ions/deletions/lookups.</div><div><br></div><div>My thought is that sorted =
collections should retain their ordering whenever possible.</div><div><br><=
/div><div><span class=3D""><div>scala&gt; val set =3D SortedSet(1,2,3)(ord=
=3DOrdering.<wbr>Int.reverse)</div><div>set: scala.collection.SortedSet[<wb=
r>Int] =3D TreeSet(3, 2, 1)</div><div><br></div></span><div>scala&gt; set.m=
ap(identity)</div><div>res0: scala.collection.SortedSet[<wbr>Int] =3D TreeS=
et(1, 2, 3) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0should be TreeSet(3, 2, 1)?</=
div><div><br></div><div>scala&gt; set.map(_*2)</div><div>res1: scala.collec=
tion.SortedSet[<wbr>Int] =3D TreeSet(2, 4, 6) =C2=A0 =C2=A0 =C2=A0 =C2=A0 s=
hould be TreeSet(6, 4, 2)?</div></div><div><br></div><div>and if possible</=
div><div><br></div><div><div>scala&gt; set.map(_*2)(collection.<wbr>breakOu=
t) : BitSet</div><div>res2: scala.collection.BitSet =3D BitSet(2, 4, 6) =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0should be BitSet(6, 4, 2)?</div></div><div><br></div><div>an impossib=
le case is when the type of the objects in the container changes</div><div>=
<br></div><div><div>scala&gt; set.map(&quot;a&quot; * _)</div><div>res3: sc=
ala.collection.SortedSet[<wbr>String] =3D TreeSet(a, aa, aaa) =C2=A0 =C2=A0=
 =C2=A0 =C2=A0this seems like correct behavior</div></div><div><br></div></=
div><br><div class=3D"gmail_quote"><div><div class=3D"h5"><div dir=3D"ltr">=
On Mon, Nov 28, 2016 at 10:34 PM Vlad Patryshev &lt;<a href=3D"mailto:vpatr=
[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:<br><=
/div></div></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class=3D"h5"><div=
 dir=3D"ltr" class=3D"m_-4798312560682989803gmail_msg">It was a pretty nice=
 (counter-)example, but I wonder what is &quot;SortedSet&quot;? And of cour=
se the next question will be - how should map be defined on &quot;SortedSet=
&quot;?<div class=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-47983=
12560682989803gmail_msg"></div><div class=3D"m_-4798312560682989803gmail_ms=
g">It&#39;s not a joke, it&#39;s a serious question.</div></div><div class=
=3D"gmail_extra m_-4798312560682989803gmail_msg"><br class=3D"m_-4798312560=
682989803gmail_msg" clear=3D"all"><div class=3D"m_-4798312560682989803gmail=
_msg"><div class=3D"m_-4798312560682989803m_-5042556665519706739gmail_signa=
ture m_-4798312560682989803gmail_msg" data-smartmail=3D"gmail_signature">Th=
anks,<br class=3D"m_-4798312560682989803gmail_msg">-Vlad</div></div>
<br class=3D"m_-4798312560682989803gmail_msg"><div class=3D"gmail_quote m_-=
4798312560682989803gmail_msg"></div></div><div class=3D"gmail_extra m_-4798=
312560682989803gmail_msg"><div class=3D"gmail_quote m_-4798312560682989803g=
mail_msg">On Mon, Nov 28, 2016 at 8:14 PM, Tobin Yehle <span dir=3D"ltr" cl=
ass=3D"m_-4798312560682989803gmail_msg">&lt;<a href=3D"mailto:tobinyehle@gm=
ail.com" class=3D"m_-4798312560682989803gmail_msg" target=3D"_blank">tobiny=
[email protected]</a>&gt;</span> wrote:<br class=3D"m_-4798312560682989803gmai=
l_msg"></div></div><div class=3D"gmail_extra m_-4798312560682989803gmail_ms=
g"><div class=3D"gmail_quote m_-4798312560682989803gmail_msg"><blockquote c=
lass=3D"gmail_quote m_-4798312560682989803gmail_msg" style=3D"margin:0 0 0 =
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr" class=3D=
"m_-4798312560682989803gmail_msg"><div class=3D"m_-4798312560682989803gmail=
_msg">Not sure if I&#39;m really posting this in the right place, but:</div=
><div class=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-47983125606=
82989803gmail_msg"></div>Calling map on a collection that requires an impli=
cit ordering results in some surprising behavior. For example:<div class=3D=
"m_-4798312560682989803gmail_msg"><div class=3D"m_-4798312560682989803gmail=
_msg"><br class=3D"m_-4798312560682989803gmail_msg"></div><div class=3D"m_-=
4798312560682989803m_-5042556665519706739m_3440269965916649927prettyprint m=
_-4798312560682989803gmail_msg" style=3D"background-color:rgb(250,250,250);=
border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap=
:break-word"><code class=3D"m_-4798312560682989803m_-5042556665519706739m_3=
440269965916649927prettyprint m_-4798312560682989803gmail_msg"><div class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927subpre=
ttyprint m_-4798312560682989803gmail_msg"><span style=3D"color:#000" class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled=
-by-prettify m_-4798312560682989803gmail_msg">scala</span><span style=3D"co=
lor:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965=
916649927styled-by-prettify m_-4798312560682989803gmail_msg">&gt;</span><sp=
an style=3D"color:#000" class=3D"m_-4798312560682989803m_-50425566655197067=
39m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">=
 val </span><span style=3D"color:#008" class=3D"m_-4798312560682989803m_-50=
42556665519706739m_3440269965916649927styled-by-prettify m_-479831256068298=
9803gmail_msg">set</span><span style=3D"color:#000" class=3D"m_-47983125606=
82989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47=
98312560682989803gmail_msg"> </span><span style=3D"color:#660" class=3D"m_-=
4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pre=
ttify m_-4798312560682989803gmail_msg">=3D</span><span style=3D"color:#000"=
 class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927=
styled-by-prettify m_-4798312560682989803gmail_msg"> </span><span style=3D"=
color:#606" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699=
65916649927styled-by-prettify m_-4798312560682989803gmail_msg">SortedSet</s=
pan><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665=
519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmai=
l_msg">(</span><span style=3D"color:#066" class=3D"m_-4798312560682989803m_=
-5042556665519706739m_3440269965916649927styled-by-prettify m_-479831256068=
2989803gmail_msg">1</span><span style=3D"color:#660" class=3D"m_-4798312560=
682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-4=
798312560682989803gmail_msg">,</span><span style=3D"color:#066" class=3D"m_=
-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pr=
ettify m_-4798312560682989803gmail_msg">2</span><span style=3D"color:#660" =
class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927s=
tyled-by-prettify m_-4798312560682989803gmail_msg">,</span><span style=3D"c=
olor:#066" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996=
5916649927styled-by-prettify m_-4798312560682989803gmail_msg">3</span><span=
 style=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665519706739=
m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">)(=
</span><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556=
665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803g=
mail_msg">ord</span><span style=3D"color:#660" class=3D"m_-4798312560682989=
803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-4798312=
560682989803gmail_msg">=3D</span><span style=3D"color:#606" class=3D"m_-479=
8312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pretti=
fy m_-4798312560682989803gmail_msg">Ordering</span><span style=3D"color:#66=
0" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166499=
27styled-by-prettify m_-4798312560682989803gmail_msg">.</span><span style=
=3D"color:#606" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440=
269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"><wbr>Int=
</span><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556=
665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803g=
mail_msg">.</span><span style=3D"color:#000" class=3D"m_-479831256068298980=
3m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-479831256=
0682989803gmail_msg">reverse</span><span style=3D"color:#660" class=3D"m_-4=
798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pret=
tify m_-4798312560682989803gmail_msg">)</span><span style=3D"color:#000" cl=
ass=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927sty=
led-by-prettify m_-4798312560682989803gmail_msg"><br class=3D"m_-4798312560=
682989803gmail_msg"></span><span style=3D"color:#008" class=3D"m_-479831256=
0682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-=
4798312560682989803gmail_msg">set</span><span style=3D"color:#660" class=3D=
"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by=
-prettify m_-4798312560682989803gmail_msg">:</span><span style=3D"color:#00=
0" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166499=
27styled-by-prettify m_-4798312560682989803gmail_msg"> scala</span><span st=
yle=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_3=
440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">.</sp=
an><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-50425566655=
19706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail=
_msg">collection</span><span style=3D"color:#660" class=3D"m_-4798312560682=
989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-4798=
312560682989803gmail_msg">.</span><span style=3D"color:#606" class=3D"m_-47=
98312560682989803m_-5042556665519706739m_3440269965916649927styled-by-prett=
ify m_-4798312560682989803gmail_msg">SortedSet</span><span style=3D"color:#=
660" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996591664=
9927styled-by-prettify m_-4798312560682989803gmail_msg">[</span><span style=
=3D"color:#606" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440=
269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">Int</spa=
n><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-504255666551=
9706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_=
msg"><wbr>]</span><span style=3D"color:#000" class=3D"m_-479831256068298980=
3m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-479831256=
0682989803gmail_msg"> </span><span style=3D"color:#660" class=3D"m_-4798312=
560682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m=
_-4798312560682989803gmail_msg">=3D</span><span style=3D"color:#000" class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled=
-by-prettify m_-4798312560682989803gmail_msg"> </span><span style=3D"color:=
#606" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166=
49927styled-by-prettify m_-4798312560682989803gmail_msg">TreeSet</span><spa=
n style=3D"color:#660" class=3D"m_-4798312560682989803m_-504255666551970673=
9m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">(=
</span><span style=3D"color:#066" class=3D"m_-4798312560682989803m_-5042556=
665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803g=
mail_msg">3</span><span style=3D"color:#660" class=3D"m_-479831256068298980=
3m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-479831256=
0682989803gmail_msg">,</span><span style=3D"color:#000" class=3D"m_-4798312=
560682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m=
_-4798312560682989803gmail_msg"> </span><span style=3D"color:#066" class=3D=
"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by=
-prettify m_-4798312560682989803gmail_msg">2</span><span style=3D"color:#66=
0" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166499=
27styled-by-prettify m_-4798312560682989803gmail_msg">,</span><span style=
=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440=
269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"> </span>=
<span style=3D"color:#066" class=3D"m_-4798312560682989803m_-50425566655197=
06739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_ms=
g">1</span><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-504=
2556665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989=
803gmail_msg">)</span><span style=3D"color:#000" class=3D"m_-47983125606829=
89803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47983=
12560682989803gmail_msg"><br class=3D"m_-4798312560682989803gmail_msg"><br =
class=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-47983125606829898=
03gmail_msg">scala</span><span style=3D"color:#660" class=3D"m_-47983125606=
82989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47=
98312560682989803gmail_msg">&gt;</span><span style=3D"color:#000" class=3D"=
m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-=
prettify m_-4798312560682989803gmail_msg"> </span><span style=3D"color:#008=
" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996591664992=
7styled-by-prettify m_-4798312560682989803gmail_msg">set</span><span style=
=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440=
269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">.</span>=
<span style=3D"color:#000" class=3D"m_-4798312560682989803m_-50425566655197=
06739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_ms=
g">firstKey </span><span style=3D"color:#660" class=3D"m_-47983125606829898=
03m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47983125=
60682989803gmail_msg">=3D=3D</span><span style=3D"color:#000" class=3D"m_-4=
798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pret=
tify m_-4798312560682989803gmail_msg"> </span><span style=3D"color:#008" cl=
ass=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927sty=
led-by-prettify m_-4798312560682989803gmail_msg">set</span><span style=3D"c=
olor:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996=
5916649927styled-by-prettify m_-4798312560682989803gmail_msg">.</span><span=
 style=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739=
m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">ma=
p</span><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-504255=
6665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803=
gmail_msg">(</span><span style=3D"color:#000" class=3D"m_-47983125606829898=
03m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47983125=
60682989803gmail_msg">identity</span><span style=3D"color:#660" class=3D"m_=
-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pr=
ettify m_-4798312560682989803gmail_msg">).</span><span style=3D"color:#000"=
 class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927=
styled-by-prettify m_-4798312560682989803gmail_msg">firstKey<br class=3D"m_=
-4798312560682989803gmail_msg">res0</span><span style=3D"color:#660" class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled=
-by-prettify m_-4798312560682989803gmail_msg">:</span><span style=3D"color:=
#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166=
49927styled-by-prettify m_-4798312560682989803gmail_msg"> </span><span styl=
e=3D"color:#606" class=3D"m_-4798312560682989803m_-5042556665519706739m_344=
0269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">Boolean=
</span><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556=
665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803g=
mail_msg"> </span><span style=3D"color:#660" class=3D"m_-479831256068298980=
3m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-479831256=
0682989803gmail_msg">=3D</span><span style=3D"color:#000" class=3D"m_-47983=
12560682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify=
 m_-4798312560682989803gmail_msg"> </span><span style=3D"color:#008" class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled=
-by-prettify m_-4798312560682989803gmail_msg">false</span></div></code></di=
v><div class=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-4798312560=
682989803gmail_msg"></div></div><div class=3D"m_-4798312560682989803gmail_m=
sg">My feeling is that mapping the identity function over any collection sh=
ould not change anything.</div><div class=3D"m_-4798312560682989803gmail_ms=
g"><br class=3D"m_-4798312560682989803gmail_msg"></div><div class=3D"m_-479=
8312560682989803gmail_msg">In this case it is clear what is happening. The =
CanBuildFrom provided by SortedSet is pulling an Ordering instance out of p=
redef (Ordering.Int) instead of using the ordering from the origin collecti=
on.</div><div class=3D"m_-4798312560682989803m_-5042556665519706739m_344026=
9965916649927prettyprint m_-4798312560682989803gmail_msg" style=3D"backgrou=
nd-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;=
border-width:1px;word-wrap:break-word"><code class=3D"m_-479831256068298980=
3m_-5042556665519706739m_3440269965916649927prettyprint m_-4798312560682989=
803gmail_msg"><div class=3D"m_-4798312560682989803m_-5042556665519706739m_3=
440269965916649927subprettyprint m_-4798312560682989803gmail_msg"><span sty=
le=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_34=
40269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">scala<=
/span><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-50425566=
65519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gm=
ail_msg">&gt;</span><span style=3D"color:#000" class=3D"m_-4798312560682989=
803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-4798312=
560682989803gmail_msg"> </span><span style=3D"color:#008" class=3D"m_-47983=
12560682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify=
 m_-4798312560682989803gmail_msg">set</span><span style=3D"color:#660" clas=
s=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927style=
d-by-prettify m_-4798312560682989803gmail_msg">.</span><span style=3D"color=
:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916=
649927styled-by-prettify m_-4798312560682989803gmail_msg">toList<br class=
=3D"m_-4798312560682989803gmail_msg">res1</span><span style=3D"color:#660" =
class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927s=
tyled-by-prettify m_-4798312560682989803gmail_msg">:</span><span style=3D"c=
olor:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996=
5916649927styled-by-prettify m_-4798312560682989803gmail_msg"> </span><span=
 style=3D"color:#606" class=3D"m_-4798312560682989803m_-5042556665519706739=
m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">Li=
st</span><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-50425=
56665519706739m_3440269965916649927styled-by-prettify m_-479831256068298980=
3gmail_msg">[</span><span style=3D"color:#606" class=3D"m_-4798312560682989=
803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-4798312=
560682989803gmail_msg">Int</span><span style=3D"color:#660" class=3D"m_-479=
8312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pretti=
fy m_-4798312560682989803gmail_msg">]</span><span style=3D"color:#000" clas=
s=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927style=
d-by-prettify m_-4798312560682989803gmail_msg"> </span><span style=3D"color=
:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916=
649927styled-by-prettify m_-4798312560682989803gmail_msg">=3D</span><span s=
tyle=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_=
3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"> </s=
pan><span style=3D"color:#606" class=3D"m_-4798312560682989803m_-5042556665=
519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmai=
l_msg">List</span><span style=3D"color:#660" class=3D"m_-479831256068298980=
3m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-479831256=
0682989803gmail_msg">(</span><span style=3D"color:#066" class=3D"m_-4798312=
560682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m=
_-4798312560682989803gmail_msg">3</span><span style=3D"color:#660" class=3D=
"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by=
-prettify m_-4798312560682989803gmail_msg">,</span><span style=3D"color:#00=
0" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166499=
27styled-by-prettify m_-4798312560682989803gmail_msg"> </span><span style=
=3D"color:#066" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440=
269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">2</span>=
<span style=3D"color:#660" class=3D"m_-4798312560682989803m_-50425566655197=
06739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_ms=
g">,</span><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-504=
2556665519706739m_3440269965916649927styled-by-prettify m_-4798312560682989=
803gmail_msg"> </span><span style=3D"color:#066" class=3D"m_-47983125606829=
89803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47983=
12560682989803gmail_msg">1</span><span style=3D"color:#660" class=3D"m_-479=
8312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pretti=
fy m_-4798312560682989803gmail_msg">)</span><span style=3D"color:#000" clas=
s=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927style=
d-by-prettify m_-4798312560682989803gmail_msg"><br class=3D"m_-479831256068=
2989803gmail_msg"><br class=3D"m_-4798312560682989803gmail_msg"><br class=
=3D"m_-4798312560682989803gmail_msg">scala</span><span style=3D"color:#660"=
 class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927=
styled-by-prettify m_-4798312560682989803gmail_msg">&gt;</span><span style=
=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_3440=
269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"> </span>=
<span style=3D"color:#008" class=3D"m_-4798312560682989803m_-50425566655197=
06739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_ms=
g">set</span><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-5=
042556665519706739m_3440269965916649927styled-by-prettify m_-47983125606829=
89803gmail_msg">.</span><span style=3D"color:#000" class=3D"m_-479831256068=
2989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-479=
8312560682989803gmail_msg">map</span><span style=3D"color:#660" class=3D"m_=
-4798312560682989803m_-5042556665519706739m_3440269965916649927styled-by-pr=
ettify m_-4798312560682989803gmail_msg">(</span><span style=3D"color:#000" =
class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927s=
tyled-by-prettify m_-4798312560682989803gmail_msg">identity</span><span sty=
le=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_34=
40269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">).</sp=
an><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-50425566655=
19706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail=
_msg">toList<br class=3D"m_-4798312560682989803gmail_msg">res2</span><span =
style=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m=
_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">:</=
span><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-504255666=
5519706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gma=
il_msg"> </span><span style=3D"color:#606" class=3D"m_-4798312560682989803m=
_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47983125606=
82989803gmail_msg">List</span><span style=3D"color:#660" class=3D"m_-479831=
2560682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify =
m_-4798312560682989803gmail_msg">[</span><span style=3D"color:#606" class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled=
-by-prettify m_-4798312560682989803gmail_msg">Int</span><span style=3D"colo=
r:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996591=
6649927styled-by-prettify m_-4798312560682989803gmail_msg">]</span><span st=
yle=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_3=
440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"> </sp=
an><span style=3D"color:#660" class=3D"m_-4798312560682989803m_-50425566655=
19706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail=
_msg">=3D</span><span style=3D"color:#000" class=3D"m_-4798312560682989803m=
_-5042556665519706739m_3440269965916649927styled-by-prettify m_-47983125606=
82989803gmail_msg"> </span><span style=3D"color:#606" class=3D"m_-479831256=
0682989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-=
4798312560682989803gmail_msg">List</span><span style=3D"color:#660" class=
=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styled=
-by-prettify m_-4798312560682989803gmail_msg">(</span><span style=3D"color:=
#066" class=3D"m_-4798312560682989803m_-5042556665519706739m_34402699659166=
49927styled-by-prettify m_-4798312560682989803gmail_msg">1</span><span styl=
e=3D"color:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_344=
0269965916649927styled-by-prettify m_-4798312560682989803gmail_msg">,</span=
><span style=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519=
706739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_m=
sg"> </span><span style=3D"color:#066" class=3D"m_-4798312560682989803m_-50=
42556665519706739m_3440269965916649927styled-by-prettify m_-479831256068298=
9803gmail_msg">2</span><span style=3D"color:#660" class=3D"m_-4798312560682=
989803m_-5042556665519706739m_3440269965916649927styled-by-prettify m_-4798=
312560682989803gmail_msg">,</span><span style=3D"color:#000" class=3D"m_-47=
98312560682989803m_-5042556665519706739m_3440269965916649927styled-by-prett=
ify m_-4798312560682989803gmail_msg"> </span><span style=3D"color:#066" cla=
ss=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927styl=
ed-by-prettify m_-4798312560682989803gmail_msg">3</span><span style=3D"colo=
r:#660" class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996591=
6649927styled-by-prettify m_-4798312560682989803gmail_msg">)</span><span st=
yle=3D"color:#000" class=3D"m_-4798312560682989803m_-5042556665519706739m_3=
440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"><br c=
lass=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-479831256068298980=
3gmail_msg"></span><span class=3D"m_-4798312560682989803m_-5042556665519706=
739m_3440269965916649927styled-by-prettify m_-4798312560682989803gmail_msg"=
><font class=3D"m_-4798312560682989803gmail_msg" color=3D"#000000"><div cla=
ss=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649927subp=
rettyprint m_-4798312560682989803gmail_msg">scala&gt; set.ordering</div><di=
v class=3D"m_-4798312560682989803m_-5042556665519706739m_344026996591664992=
7subprettyprint m_-4798312560682989803gmail_msg">res3: Ordering[Int] =3D sc=
ala.math.Ordering$$anon$4@<wbr>3ff3275b</div><div class=3D"m_-4798312560682=
989803m_-5042556665519706739m_3440269965916649927subprettyprint m_-47983125=
60682989803gmail_msg"><br class=3D"m_-4798312560682989803gmail_msg"></div><=
div class=3D"m_-4798312560682989803m_-5042556665519706739m_3440269965916649=
927subprettyprint m_-4798312560682989803gmail_msg">scala&gt; set.map(identi=
ty).ordering</div><div class=3D"m_-4798312560682989803m_-504255666551970673=
9m_3440269965916649927subprettyprint m_-4798312560682989803gmail_msg">res4:=
 Ordering[Int] =3D scala.math.Ordering$Int$@<wbr>7fa85a55</div></font></spa=
n></div></code></div><div class=3D"m_-4798312560682989803gmail_msg"><div cl=
ass=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-4798312560682989803=
gmail_msg"></div><div class=3D"m_-4798312560682989803gmail_msg">I think thi=
s can be fixed by providing a more specific CanBuildFrom instance to be use=
d when mapping between two sorted collections that contain the same type.</=
div></div><div class=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-47=
98312560682989803gmail_msg"></div><div class=3D"m_-4798312560682989803gmail=
_msg">i.e. Provide a CanBuildFrom[Sorted[K, _], K, Sorted[K, _]] somewhere =
that has precedence over the more generic usual CanBuildFrom[CC[_], A, CC[A=
]]</div><div class=3D"m_-4798312560682989803gmail_msg"><br class=3D"m_-4798=
312560682989803gmail_msg"></div><div class=3D"m_-4798312560682989803gmail_m=
sg">I&#39;m not sure how it could be done, but the static overloading resol=
ution rules make this possible, I think.</div></div></blockquote></div></di=
v><div class=3D"gmail_extra m_-4798312560682989803gmail_msg"><div class=3D"=
gmail_quote m_-4798312560682989803gmail_msg"><blockquote class=3D"gmail_quo=
te m_-4798312560682989803gmail_msg" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><span class=3D"m_-4798312560682989803m_-50=
42556665519706739HOEnZb m_-4798312560682989803gmail_msg"><font class=3D"m_-=
4798312560682989803gmail_msg" color=3D"#888888">

<p class=3D"m_-4798312560682989803gmail_msg"></p>

-- <br class=3D"m_-4798312560682989803gmail_msg">
You received this message because you are subscribed to the Google Groups &=
quot;scala-language&quot; group.<br class=3D"m_-4798312560682989803gmail_ms=
g">
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]" clas=
s=3D"m_-4798312560682989803gmail_msg" target=3D"_blank">scala-language+unsu=
bscribe@<wbr>googlegroups.com</a>.</font></span></blockquote></div></div><d=
iv class=3D"gmail_extra m_-4798312560682989803gmail_msg"><div class=3D"gmai=
l_quote m_-4798312560682989803gmail_msg"><blockquote class=3D"gmail_quote m=
_-4798312560682989803gmail_msg" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex"><span class=3D"m_-4798312560682989803m_-504255=
6665519706739HOEnZb m_-4798312560682989803gmail_msg"><font class=3D"m_-4798=
312560682989803gmail_msg" color=3D"#888888"><br class=3D"m_-479831256068298=
9803gmail_msg">
For more options, visit <a href=3D"https://groups.google.com/d/optout" clas=
s=3D"m_-4798312560682989803gmail_msg" target=3D"_blank">https://groups.goog=
le.com/d/<wbr>optout</a>.<br class=3D"m_-4798312560682989803gmail_msg">
</font></span></blockquote></div></div>

<p class=3D"m_-4798312560682989803gmail_msg"></p>

-- <br class=3D"m_-4798312560682989803gmail_msg"></div></div>
You received this message because you are subscribed to a topic in the Goog=
le Groups &quot;scala-language&quot; group.<br class=3D"m_-4798312560682989=
803gmail_msg">
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
d/topic/scala-language/Q5A1TTEZN4Q/unsubscribe" class=3D"m_-479831256068298=
9803gmail_msg" target=3D"_blank">https://groups.google.com/d/<wbr>topic/sca=
la-language/<wbr>Q5A1TTEZN4Q/unsubscribe</a>.<br class=3D"m_-47983125606829=
89803gmail_msg">
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:[email protected]" class=3D"m_-4798312=
560682989803gmail_msg" target=3D"_blank">scala-language+unsubscribe@<wbr>go=
oglegroups.com</a>.<span class=3D""><br class=3D"m_-4798312560682989803gmai=
l_msg">
For more options, visit <a href=3D"https://groups.google.com/d/optout" clas=
s=3D"m_-4798312560682989803gmail_msg" target=3D"_blank">https://groups.goog=
le.com/d/<wbr>optout</a>.<br class=3D"m_-4798312560682989803gmail_msg">
</span></blockquote></div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;scala-language&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]" targ=
et=3D"_blank">scala-language+unsubscribe@<wbr>googlegroups.com</a>.<br>
For more options, visit <a href=3D"https://groups.google.com/d/optout" targ=
et=3D"_blank">https://groups.google.com/d/<wbr>optout</a>.<br>
</div></div></blockquote></div><br><br clear=3D"all"><br>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><d=
iv><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div>Oliver=
 Ruebenacker<br></div><div>Senior Software Engineer, <a href=3D"http://www.=
type2diabetesgenetics.org/" target=3D"_blank">Diabetes Portal</a>, <a href=
=3D"http://www.broadinstitute.org/" target=3D"_blank">Broad Institute</a><b=
r></div><br></div></div></div></div></div></div></div></div>
</div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;scala-language&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">scal=
[email protected]</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />

--001a114a886850385005427211bc--