Also, (since I believe that sort is stable), (map last . group . sort) should work, and may have different performance characteristics (but requires an Ord constraint).<br><br><div class="gmail_quote">On Sat, Jun 4, 2011 at 12:52 PM, Christopher Howard <span dir="ltr"><<a href="mailto:christopher.howard@frigidcode.com">christopher.howard@frigidcode.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On 06/04/2011 12:20 AM, Iustin Pop wrote:<br>
> On Fri, Jun 03, 2011 at 11:49:01PM -0800, Christopher Howard wrote:<br>
>> On 06/03/2011 11:37 PM, Christopher Howard wrote:<br>
>>> Weird request: For a certain application, the "nub" function from<br>
>>> Data.List is exactly what I need... almost. Nub removes duplicates,<br>
>>> keeping the /first/ occurrence of each element. However, I need a<br>
>>> function that removes duplicates, keeping the /second/ occurrence of<br>
>>> each element. There wouldn't happen to be a function already that does<br>
>>> this, would there?<br>
>>><br>
>>> I'm working with a custom type which is a member of Eq, but some of the<br>
>>> data in the type is not used in the comparison. So it is important which<br>
>>> of the two "duplicates" are actually saved.<br>
>>><br>
>><br>
>> I should qualify this: By "second" I mean "last". Of course, it is<br>
>> possible for there to be more than one duplicate of any given element in<br>
>> a list. E.g., if there are three identical elements in a list, I want<br>
>> the third one, not the second one.<br>
><br>
> In that case, can't you simply revert the list, nub it, then revert<br>
> again (i.e. reverse . nub . reverse)?<br>
><br>
> regards,<br>
> iustin<br>
><br>
<br>
</div>@iustin: Thanks, that should work well enough.<br>
<br>
@Edwards: I'm not familiar with Data.Set, so I do not understand your<br>
solution.<br>
<div class="im"><br>
--<br>
<a href="http://frigidcode.com" target="_blank">frigidcode.com</a><br>
<a href="http://theologia.indicium.us" target="_blank">theologia.indicium.us</a><br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div> Alex R</div></div><br>