sequences.extras: adding ?trim.
parent
75778c89c1
commit
60927a7925
|
@ -77,3 +77,6 @@ IN: sequences.extras.tests
|
|||
|
||||
{ { } } [ "ABC" [ ] { } trim-as ] unit-test
|
||||
{ "ABC" } [ { 32 65 66 67 32 } [ blank? ] "" trim-as ] unit-test
|
||||
|
||||
{ t } [ "ABC" dup [ blank? ] ?trim [ identity-hashcode ] bi@ = ] unit-test
|
||||
{ "ABC" } [ " ABC " [ blank? ] ?trim ] unit-test
|
||||
|
|
|
@ -201,3 +201,15 @@ PRIVATE>
|
|||
|
||||
: trim-as ( ... seq quot: ( ... elt -- ... ? ) exemplar -- ... newseq )
|
||||
[ trim-slice ] [ like ] bi* ; inline
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: last-unsafe ( seq -- elt ) [ length 1 - ] [ nth-unsafe ] bi ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: ?trim ( ... seq quot: ( ... elt -- ... ? ) -- ... seq/newseq )
|
||||
over empty? [ drop ] [
|
||||
over [ first-unsafe ] [ last-unsafe ] bi pick bi@ or
|
||||
[ trim ] [ drop ] if
|
||||
] if ; inline
|
||||
|
|
Loading…
Reference in New Issue