From c6ce216e0367b5bb61acca288d1651b2f8be2a11 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 27 Dec 2007 16:38:54 -0600 Subject: [PATCH] Add ?first .. ?fourth to sequences.lib --- extra/sequences/lib/lib-tests.factor | 7 +++++++ extra/sequences/lib/lib.factor | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/extra/sequences/lib/lib-tests.factor b/extra/sequences/lib/lib-tests.factor index 72cf9ad9c4..717f463c45 100644 --- a/extra/sequences/lib/lib-tests.factor +++ b/extra/sequences/lib/lib-tests.factor @@ -46,3 +46,10 @@ math.functions tools.test strings ; [ { { 0 0 } { 1 0 } { 0 1 } { 1 1 } } ] [ 2 2 exact-strings ] unit-test [ t ] [ "ab" 4 strings [ >string ] map "abab" swap member? ] unit-test [ { { } { 1 } { 2 } { 1 2 } } ] [ { 1 2 } power-set ] unit-test + +[ f ] [ { } ?first ] unit-test +[ f ] [ { } ?fourth ] unit-test +[ 1 ] [ { 1 2 3 } ?first ] unit-test +[ 2 ] [ { 1 2 3 } ?second ] unit-test +[ 3 ] [ { 1 2 3 } ?third ] unit-test +[ f ] [ { 1 2 3 } ?fourth ] unit-test diff --git a/extra/sequences/lib/lib.factor b/extra/sequences/lib/lib.factor index ea6fdd141b..442b5f317d 100644 --- a/extra/sequences/lib/lib.factor +++ b/extra/sequences/lib/lib.factor @@ -126,3 +126,8 @@ PRIVATE> : human-sort ( seq -- newseq ) [ dup [ digit? ] [ string>number ] cut-all ] { } map>assoc sort-values keys ; + +: ?first ( seq -- first/f ) 0 swap ?nth ; inline +: ?second ( seq -- second/f ) 1 swap ?nth ; inline +: ?third ( seq -- third/f ) 2 swap ?nth ; inline +: ?fourth ( seq -- fourth/f ) 3 swap ?nth ; inline