From c2aca44b4a9c12c0b4f1a25c83f889b93af92828 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 29 Jan 2011 00:18:36 -0500 Subject: [PATCH] sequences: nths should return a sequence of the same type as the original (reported by Jon Harper) --- core/sequences/sequences-tests.factor | 2 ++ core/sequences/sequences.factor | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/sequences/sequences-tests.factor b/core/sequences/sequences-tests.factor index 175ab252e1..586e312edb 100644 --- a/core/sequences/sequences-tests.factor +++ b/core/sequences/sequences-tests.factor @@ -255,6 +255,8 @@ unit-test [ { "a" "b" "c" "d" } ] [ { 0 1 2 3 } { "a" "b" "c" "d" } nths ] unit-test [ { "d" "c" "b" "a" } ] [ { 3 2 1 0 } { "a" "b" "c" "d" } nths ] unit-test [ { "d" "a" "b" "c" } ] [ { 3 0 1 2 } { "a" "b" "c" "d" } nths ] unit-test + +[ "dac" ] [ { 3 0 2 } "abcd" nths ] unit-test TUPLE: bogus-hashcode ; diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 55398ff02b..493365db1a 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2005, 2010 Slava Pestov, Daniel Ehrenberg. +! Copyright (C) 2005, 2011 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel kernel.private slots.private math math.private math.order ; @@ -559,7 +559,7 @@ PRIVATE> [ [ (indices) ] 2curry each-index ] keep ; : nths ( indices seq -- seq' ) - [ nth ] curry map ; + [ [ nth ] curry ] keep map-as ; : any? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? ) find drop >boolean ; inline