From: Doug Coleman Date: Thu, 25 Aug 2022 22:06:07 +0000 (-0400) Subject: sequences: fix map-from and map-from-as X-Git-Tag: 0.99~590 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=17a6d008ef4699ebe74daa6a67b6698f5d7e5b70 sequences: fix map-from and map-from-as --- diff --git a/core/sequences/sequences-tests.factor b/core/sequences/sequences-tests.factor index 0eada182af..6d0a132139 100644 --- a/core/sequences/sequences-tests.factor +++ b/core/sequences/sequences-tests.factor @@ -444,6 +444,12 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ; BV{ 11 23 35 } } [ { 11 22 33 } [ + ] BV{ } map-index-as ] unit-test +{ { 0 400 900 } } +[ { 10 20 30 } [ sq ] 1 map-from ] unit-test + +{ V{ 0 400 900 } } +[ { 10 20 30 } [ sq ] 1 V{ } map-from-as ] unit-test + { t } [ { } { 99 88 } [ <= ] 2all? ] unit-test { f } [ { } { 99 88 } [ <= ] 2any? ] unit-test diff --git a/extra/sequences/extras/extras.factor b/extra/sequences/extras/extras.factor index c2fe02c644..f5a2a81823 100644 --- a/extra/sequences/extras/extras.factor +++ b/extra/sequences/extras/extras.factor @@ -269,10 +269,10 @@ PRIVATE> : setup-each-from ( seq quot -- n quot ) [ [ length ] keep [ nth-unsafe ] curry ] dip compose ; inline -: map-from-as ( ... from seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq ) - [ sequence-operator ] dip map-integers-as ; inline +: map-from-as ( ... seq quot: ( ... elt -- ... newelt ) from exemplar -- ... newseq ) + -rotd [ sequence-operator nipd ] dip map-integers-from-as ; inline -: map-from ( ... from seq quot: ( ... elt -- ... newelt ) -- ... newseq ) +: map-from ( ... seq quot: ( ... elt -- ... newelt ) from -- ... newseq ) pick map-from-as ; inline : map-if ( ... seq if-quot: ( ... elt -- ... ? ) map-quot: ( ... elt -- ... newelt ) -- ... newseq )