sequences.interleaved: adding a interleaved sequence.

windows-high-dpi
John Benediktsson 2018-02-15 17:33:34 -08:00
parent fb0a6c6c5e
commit 192cf2a352
4 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1 @@
John Benediktsson

View File

@ -0,0 +1,7 @@
USING: sequences.interleaved strings tools.test ;
{ "" } [ "" CHAR: _ <interleaved> >string ] unit-test
{ "a" } [ "a" CHAR: _ <interleaved> >string ] unit-test
{ "a_b" } [ "ab" CHAR: _ <interleaved> >string ] unit-test
{ "a_b_c" } [ "abc" CHAR: _ <interleaved> >string ] unit-test
{ "a_b_c_d" } [ "abcd" CHAR: _ <interleaved> >string ] unit-test

View File

@ -0,0 +1,26 @@
! Copyright (C) 2018 John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel math math.order sequences
sequences.private ;
IN: sequences.interleaved
TUPLE: interleaved { seq read-only } { elt read-only } ;
C: <interleaved> interleaved
M: interleaved length seq>> length dup 1 - + 0 max ;
M: interleaved nth-unsafe
over even? [
[ 2 / ] [ seq>> ] bi* nth-unsafe
] [
nip elt>>
] if ;
M: interleaved like seq>> like ;
M: interleaved new-sequence seq>> new-sequence ;
INSTANCE: interleaved immutable-sequence

View File

@ -0,0 +1 @@
Interleaved sequences