]> gitweb.factorcode.org Git - factor.git/commitdiff
extras: remove circular dependency
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 25 Feb 2023 19:15:47 +0000 (13:15 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Feb 2023 23:11:04 +0000 (17:11 -0600)
extra/assocs/extras/extras.factor
extra/sequences/extras/extras.factor

index adf8ceb81a445c056c5016008a27696b840f0a3b..8ac28df46eebe6dfbbd04a8339952d500caad8f6 100644 (file)
@@ -1,9 +1,12 @@
 ! Copyright (C) 2012 John Benediktsson, Doug Coleman
 ! See https://factorcode.org/license.txt for BSD license
 USING: arrays assocs assocs.private kernel math math.statistics
-sequences sequences.extras sets ;
+sequences sets ;
 IN: assocs.extras
 
+: change-of ( ..a assoc key quot: ( ..a value -- ..b newvalue ) -- ..b assoc )
+    [ [ of ] dip call ] 2keepd rot set-of ; inline
+
 : of* ( assoc key -- value/f ? ) swap at* ; inline
 
 : of+ ( assoc key n -- assoc ) '[ 0 or _ + ] change-of ; inline
@@ -21,17 +24,10 @@ IN: assocs.extras
 : rename-of ( assoc key newkey -- assoc )
     [ delete-of* ] dip swap [ set-of ] [ 2drop ] if ;
 
-: at+* ( n key assoc -- old new ) [ 0 or [ + ] keep swap dup ] change-at ; inline
-
-: inc-at* ( key assoc -- old new ) [ 1 ] 2dip at+* ; inline
-
 : inc-of ( assoc key -- assoc ) 1 of+ ; inline
 
 : inc-of* ( assoc key -- assoc old new ) 1 of+* ; inline
 
-: change-of ( ..a assoc key quot: ( ..a value -- ..b newvalue ) -- ..b assoc )
-    [ [ of ] dip call ] 2keepd rot set-of ; inline
-
 : ?change-of ( ..a assoc key quot: ( ..a value -- ..b newvalue ) -- ..b assoc )
     [ set-of ] compose [ 2dup ?of ] dip [ 2drop ] if ; inline
 
@@ -57,12 +53,6 @@ IN: assocs.extras
 : deep-set-of ( assoc seq elt -- )
     [ deep-of-but-last ] dip spin set-at ; inline
 
-: zip-longest-with ( seq1 seq2 fill -- assoc )
-    pad-longest zip ;
-
-: zip-longest ( seq1 seq2 -- assoc )
-    f zip-longest-with ;
-
 : substitute! ( seq assoc -- seq )
     substituter map! ;
 
index 39d03fa9df24ad142ebdc3798ac4822d015f55ee..a36caa74de56b87d4d373fe40cdfb96c3972788e 100644 (file)
@@ -1,3 +1,4 @@
+
 USING: accessors arrays assocs combinators generalizations
 grouping growable heaps kernel math math.order ranges sequences
 sequences.private shuffle sorting splitting vectors ;
@@ -60,6 +61,12 @@ IN: sequences.extras
         pick surround-as
     ] if-zero ;
 
+: zip-longest-with ( seq1 seq2 fill -- assoc )
+    pad-longest zip ;
+
+: zip-longest ( seq1 seq2 -- assoc )
+    f zip-longest-with ;
+
 : change-nths ( ... indices seq quot: ( ... elt -- ... elt' ) -- ... )
     [ change-nth ] 2curry each ; inline
 
@@ -295,12 +302,13 @@ PRIVATE>
 : 0accumulate ( ... seq quot: ( ... prev elt -- ... next ) -- ... final newseq )
     over 0accumulate-as ; inline
 
-: occurrence-count-by ( seq quot: ( elt -- elt' ) -- hash seq' )
-    '[ nip @ over inc-at* drop ] [ H{ } clone ] 2dip 0accumulate ; inline
-
 : nth-index ( n obj seq -- i )
     [ = dup [ drop 1 - dup 0 < ] when ] with find drop nip ;
 
+: at+* ( n key assoc -- old new ) [ 0 or [ + ] keep swap dup ] change-at ; inline
+
+: inc-at* ( key assoc -- old new ) [ 1 ] 2dip at+* ; inline
+
 : progressive-index-by-as ( seq1 seq2 quot exemplar -- hash seq' )
     [
         pick length '[