From: chris.double Date: Sun, 8 Oct 2006 10:44:34 +0000 (+0000) Subject: contrib/sequences: add ?head-slice, ?tail-slice, etc X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=a7798e06d0a816e655305f44263856bf53d1570b contrib/sequences: add ?head-slice, ?tail-slice, etc --- diff --git a/contrib/sequences.factor b/contrib/sequences.factor index 4980022008..5ec775dad5 100644 --- a/contrib/sequences.factor +++ b/contrib/sequences.factor @@ -39,4 +39,13 @@ IN: sequences-contrib : trim* ( seq quot -- newseq ) [ (ltrim*) ] keep rtrim* ; : trim ( seq -- newseq ) [ blank? ] trim* ; +: ?head-slice ( seq begin -- newseq ? ) + 2dup head? [ length tail-slice t ] [ drop f ] if ; + +: ?tail-slice ( seq end -- newseq ? ) + 2dup tail? [ length head-slice* t ] [ drop f ] if ; + +: unclip-slice ( seq -- rest first ) + dup 1 tail-slice swap first ; + PROVIDE: contrib/sequences ;