From 33d96f76234630980a9985c8e76d42c7e544b071 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 6 Aug 2015 03:20:10 -0500 Subject: [PATCH] combinators.smart: Add smart combinator that outputs a seq and (length-n) more elements. --- basis/combinators/smart/smart-tests.factor | 4 ++++ basis/combinators/smart/smart.factor | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/basis/combinators/smart/smart-tests.factor b/basis/combinators/smart/smart-tests.factor index 33523a0154..ffd1e06f62 100644 --- a/basis/combinators/smart/smart-tests.factor +++ b/basis/combinators/smart/smart-tests.factor @@ -123,3 +123,7 @@ IN: combinators.smart.tests { [ + ] [ + ] } } smart-2map-reduce ] unit-test + +{ { 1 2 3 4 } 5 6 } [ [ 1 2 3 4 5 6 ] 2 output>array-n ] unit-test +{ { } 5 6 } [ [ 5 6 ] 2 output>array-n ] unit-test +{ { 1 2 } 3 4 5 6 } [ [ 1 2 3 4 5 6 ] 4 output>array-n ] unit-test diff --git a/basis/combinators/smart/smart.factor b/basis/combinators/smart/smart.factor index a620fd4cce..04bb94fde0 100644 --- a/basis/combinators/smart/smart.factor +++ b/basis/combinators/smart/smart.factor @@ -67,6 +67,13 @@ M: object infer-known* drop f ; : output>array ( quot -- array ) { } output>sequence ; inline +MACRO: output>sequence-n ( quot exemplar n -- quot ) + 3dup nip [ outputs ] dip - -rot + '[ @ [ _ _ nsequence ] _ ndip ] ; + +MACRO: output>array-n ( quot n -- array ) + '[ _ { } _ output>sequence-n ] ; + : cleave>array ( obj quots -- array ) '[ _ cleave ] output>array ; inline