]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: use with-assoc, most
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 19 Aug 2022 01:53:00 +0000 (20:53 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Feb 2023 23:11:03 +0000 (17:11 -0600)
found by `"sequences" lint-vocab`

core/assocs/assocs.factor
core/sequences/sequences.factor
extra/sequences/extras/extras.factor

index 6cebc35f87a255791abf1d7de1c443aea0a62448..d3d870a94b312f81bff891b275871c05321f8424 100644 (file)
@@ -57,9 +57,6 @@ M: assoc assoc-like drop ; inline
 : substituter ( assoc -- quot )
     [ ?at drop ] curry ; inline
 
-: with-assoc ( assoc quot: ( ..a value key assoc -- ..b ) -- quot: ( ..a key value -- ..b ) )
-    curry [ swap ] prepose ; inline
-
 PRIVATE>
 
 : assoc-find ( ... assoc quot: ( ... key value -- ... ? ) -- ... key value ? )
index 699bc8738e1b8d88e1e652f725c45fee91fd387f..b4163f7887a63c588f3d54f40d640ea60b2ead51 100644 (file)
@@ -755,8 +755,11 @@ PRIVATE>
 : last-index-from ( obj i seq -- n )
     rot [ = ] curry find-last-from drop ;
 
+: with-assoc ( assoc quot: ( ..a value key assoc -- ..b ) -- quot: ( ..a key value -- ..b ) )
+    curry [ swap ] prepose ; inline
+
 : indices ( obj seq -- indices )
-    swap [ = ] curry [ swap ] prepose V{ } clone [
+    swap [ = ] with-assoc V{ } clone [
         [ push ] curry [ [ drop ] if ] curry compose each-index
     ] keep ;
 
@@ -1049,8 +1052,8 @@ PRIVATE>
 
 : shorter? ( seq1 seq2 -- ? ) 2length < ; inline
 : longer? ( seq1 seq2 -- ? ) 2length > ; inline
-: shorter ( seq1 seq2 -- seq ) [ 2length <= ] 2keep ? ; inline
-: longer ( seq1 seq2 -- seq ) [ 2length >= ] 2keep ? ; inline
+: shorter ( seq1 seq2 -- seq ) [ 2length <= ] most ; inline
+: longer ( seq1 seq2 -- seq ) [ 2length >= ] most ; inline
 
 : head? ( seq begin -- ? )
     2dup shorter? [
@@ -1219,7 +1222,7 @@ M: repetition sum [ elt>> ] [ length>> ] bi * ; inline
 : supremum ( seq -- elt ) [ ] [ max ] map-reduce ;
 
 : map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n )
-    [ 0 ] 2dip [ dip + ] curry [ swap ] prepose each ; inline
+    [ 0 ] 2dip [ dip + ] with-assoc each ; inline
 
 : count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
     [ 1 0 ? ] compose map-sum ; inline
index 751bcec77cf1a09dabef50b3ab083ac0e819fdfb..4f9d1821f0d1e819a7d736e55a199734913d0a03 100644 (file)
@@ -531,7 +531,7 @@ PRIVATE>
     [ (reverse) ] [ like ] bi* ;
 
 : map-product ( ... seq quot: ( ... elt -- ... n ) -- ... n )
-    [ 1 ] 2dip [ dip * ] curry [ swap ] prepose each ; inline
+    [ 1 ] 2dip [ dip * ] with-assoc each ; inline
 
 : insert-nth! ( elt n seq -- )
     [ length ] keep ensure swap pick (a..b]