Wiki Diff SnippitUnique, revision #5 to tip
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.
<eucode>
include std/sequence.e
--**
-- Input a sequence, list of lines for example.
-- Output the list with no duplicates.
-- Used most often with something like sul = sort(unique(list))
--
function unique(sequence list)
return remove_dups(list, RD_INPLACE)
end function
ifdef UNITTEST then
include std/unittest.e
include std/sort.e
sequence test_source = "DAFBAGCFE"
set_test_verbosity(TEST_SHOW_ALL)
test_equal("plain unique"
,"DAFBGCE", unique(test_source))
test_equal("sorted unique"
,"ABCDEFG", sort(unique(test_source)))
test_report()
end ifdef
</eucode>
</eucode>
----
CategorySnippet
assume it has not tested more than appears here.
<eucode>
include std/sequence.e
--**
-- Input a sequence, list of lines for example.
-- Output the list with no duplicates.
-- Used most often with something like sul = sort(unique(list))
--
function unique(sequence list)
return remove_dups(list, RD_INPLACE)
end function
ifdef UNITTEST then
include std/unittest.e
include std/sort.e
sequence test_source = "DAFBAGCFE"
set_test_verbosity(TEST_SHOW_ALL)
test_equal("plain unique"
,"DAFBGCE", unique(test_source))
test_equal("sorted unique"
,"ABCDEFG", sort(unique(test_source)))
test_report()
end ifdef
</eucode>