diff --git a/core/new-sets/new-sets-tests.factor b/core/new-sets/new-sets-tests.factor index 18960f86db..b644b9a809 100644 --- a/core/new-sets/new-sets-tests.factor +++ b/core/new-sets/new-sets-tests.factor @@ -47,5 +47,7 @@ IN: new-sets.tests [ { 1 2 3 } ] [ { 1 2 2 3 3 } { } set-like ] unit-test [ { 3 2 1 } ] [ { 3 3 2 2 1 } { } set-like ] unit-test -[ { 1 2 1 } ] [ { 1 2 3 2 1 2 1 } duplicates ] unit-test +[ { 2 1 2 1 } ] [ { 1 2 3 2 1 2 1 } duplicates ] unit-test [ f ] [ HS{ 1 2 3 1 2 1 } duplicates ] unit-test + +[ H{ { 3 HS{ 1 2 } } } ] [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test diff --git a/core/new-sets/new-sets.factor b/core/new-sets/new-sets.factor index 115e0d404a..bc4e720c9c 100644 --- a/core/new-sets/new-sets.factor +++ b/core/new-sets/new-sets.factor @@ -61,12 +61,12 @@ M: set all-unique? drop t ; ] [ length ] tri + [ f fast-set ] [ length ] bi [ [ (prune) ] 2curry each ] keep ; PRIVATE> @@ -98,3 +98,9 @@ USE: vocabs.loader : combine ( sets -- set ) f [ union ] reduce ; + +: gather ( seq quot -- newseq ) + map concat members ; inline + +: adjoin-at ( value key assoc -- ) + [ [ f fast-set ] unless* [ adjoin ] keep ] change-at ;