]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: fix e/i and i/e and remove maybe-nth with suggestion from
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 26 Jul 2022 02:27:47 +0000 (21:27 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 31 Jul 2022 18:24:58 +0000 (13:24 -0500)
@mrjbq7

core/sequences/sequences.factor

index 87aa6f6465273df8662d67538e1bea44189f68dd..cf4514ff904309d0529a9fcb1899dec650abe8ec 100644 (file)
@@ -182,9 +182,6 @@ PRIVATE>
 : ?set-nth ( elt n seq -- )
     2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline
 
-: maybe-nth ( i/f seq -- elt/f )
-    over [ nth ] [ 2drop f ] if ; inline
-
 : ?first ( seq -- elt/f ) 0 swap ?nth ; inline
 : ?second ( seq -- elt/f ) 1 swap ?nth ; inline
 : ?last ( seq -- elt/f )
@@ -459,10 +456,10 @@ PRIVATE>
     [ setup-3each ] dip compose ; inline
 
 : element/index ( i/f seq -- elt/f i/f )
-    [ maybe-nth ] [ drop ] 2bi ; inline
+    '[ [ _ nth ] [ f ] if* ] keep ;
 
-: index/element ( i/f seq -- elt/f i/f )
-    [ drop ] [ maybe-nth ] 2bi ; inline
+: index/element ( i/f seq -- i/f elt/f )
+    dupd '[ _ nth ] [ f ] if* ;
 
 : (accumulate) ( seq identity quot -- identity seq quot' )
     swapd [ keepd ] curry ; inline