From 31d6fb178a5d4e3f8f4cc284d2a52c79c4add5f8 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 24 Mar 2013 19:34:39 -0700 Subject: [PATCH] combinators.extras: adding cleave-array. --- extra/combinators/extras/extras-tests.factor | 2 ++ extra/combinators/extras/extras.factor | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/extra/combinators/extras/extras-tests.factor b/extra/combinators/extras/extras-tests.factor index 6ad66adafc..873c168e41 100644 --- a/extra/combinators/extras/extras-tests.factor +++ b/extra/combinators/extras/extras-tests.factor @@ -21,3 +21,5 @@ IN: combinators.extras.tests } cond-case ] map ] unit-test + +{ { 1 2 3 } } [ 1 { [ ] [ 1 + ] [ 2 + ] } cleave-array ] unit-test diff --git a/extra/combinators/extras/extras.factor b/extra/combinators/extras/extras.factor index a5c106e40c..2787b50d2d 100644 --- a/extra/combinators/extras/extras.factor +++ b/extra/combinators/extras/extras.factor @@ -1,6 +1,7 @@ ! Copyright (C) 2013 Doug Coleman, John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays combinators kernel macros quotations sequences ; +USING: arrays combinators fry kernel macros quotations +sequences sequences.generalizations ; IN: combinators.extras : once ( quot -- ) call ; inline @@ -14,3 +15,6 @@ MACRO: cond-case ( assoc -- ) [ second [ drop ] prepose ] bi 2array ] when ] map [ cond ] curry ; + +MACRO: cleave-array ( quots -- ) + [ '[ _ cleave ] ] [ length '[ _ narray ] ] bi compose ;