Hello, all!

  I have an interesting little task for you today.

  Let's say you have a sequence of tuples, and you want to remove all tuples 
with duplicate ids, so that in the new sequence there is only one tuple with 
each id.

  Here's my solution:

TYPED: dedupe-by-hash ( seq: sequence -- seq: sequence )
    dup [ hash>> ] map >hash-set [
        [ hash>> ] dip
        [ in? ] [ delete ] 2bi
    ] curry filter ;

  This is not the first time I'm solving this task, and I begun to wonder - is 
there something similar in the Factor library?

  Is this the simplest/most efficient implementation?

  Is it possible to generalize it to work for any slot like so:

TYPED: dedupe-by-slot ( seq slot -- seq ) ?

  If this code is not in the standard library, how about adding it? Seems 
pretty useful, and not too trivial.

  What do you say?

---=====--- 
 Александр

------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to