sequences.extras: adding map-concat.
parent
f3e1dc5b98
commit
61b3c26e1b
|
@ -54,3 +54,8 @@ IN: sequences.extras.tests
|
|||
{ "llohe" } [ "hello" 2 rotate ] unit-test
|
||||
{ "hello" } [ "hello" dup 0 rotate! ] unit-test
|
||||
{ "lohel" } [ "hello" dup 3 rotate! ] unit-test
|
||||
|
||||
{ { } } [ { } [ ] map-concat ] unit-test
|
||||
{ V{ 0 0 1 0 1 2 } } [ 4 iota [ iota ] map-concat ] unit-test
|
||||
{ "abc" } [ "abc" [ 1string ] map-concat ] unit-test
|
||||
{ { 97 98 99 } } [ "abc" [ 1string ] { } map-concat-as ] unit-test
|
||||
|
|
|
@ -114,3 +114,16 @@ IN: sequences.extras
|
|||
dup end = [ drop over ] when
|
||||
2over = [ -rot nip over ] when
|
||||
] until 3drop ;
|
||||
|
||||
: appender-for ( quot exemplar -- quot' vec )
|
||||
[ length ] keep new-resizable
|
||||
[ [ push-all ] curry compose ] keep ; inline
|
||||
|
||||
: appender ( quot -- quot' vec )
|
||||
V{ } appender-for ; inline
|
||||
|
||||
: map-concat-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
|
||||
dup [ appender-for [ each ] dip ] curry dip like ; inline
|
||||
|
||||
: map-concat ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )
|
||||
over map-concat-as ; inline
|
||||
|
|
Loading…
Reference in New Issue