Historical SnippitUnique, Revision 2
there may already be a better way to do this in the euphoria 4 standard lib or in the archive, but I have used this a few times and it just works. assume it has not tested more than appears here.
include std/unittest.e --~ with define UNITTEST include std/sets.e --** -- input a sequence, list of lines for ex. -- output the list in no particular order with no duplicates -- used most often with something like sul = sort(unique(list)) -- this could/should be made more robust. --another problem is the random order of the returned list --would be better if it allowed first or last occurance to be kept --and to remove blanks and keep origional order or not care --could be easily confused by subsequences. needs more testing... -- function unique(sequence list) set slist = sequence_to_set(list) return slist --works for now end function ifdef UNITTEST then set_test_verbosity(TEST_SHOW_ALL) test_equal("sorted unique" ,"ABCDEFG", sort(unique("AABCDEFFG"))) test_report() end ifdef
- diff to current revision, view current revision history, backlinks
- Last modified Jul 07, 2009 by ne1uno