1 ! Copyright (C) 2008 Alex Chapman
2 ! Copyright (C) 2012 John Benediktsson
3 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors circular kernel math sequences sequences.private ;
5 IN: sequences.repeating
8 { circular circular read-only }
9 { length integer read-only } ;
11 : <cycles> ( seq length -- cycles )
12 [ <circular> ] dip cycles boa ;
14 : cycle ( seq length -- new-seq )
15 dupd <cycles> swap like ;
17 M: cycles length length>> ;
19 M: cycles set-length length<< ;
21 M: cycles virtual@ circular>> ;
23 M: cycles virtual-exemplar circular>> ;
25 INSTANCE: cycles virtual-sequence
28 { seq sequence read-only }
29 { times integer read-only } ;
33 M: repeats length [ seq>> length ] [ times>> ] bi * ;
35 M: repeats virtual@ [ times>> /i ] [ seq>> ] bi ;
37 M: repeats virtual-exemplar seq>> ;
39 INSTANCE: repeats immutable-sequence
41 INSTANCE: repeats virtual-sequence
43 : repeat ( seq times -- new-seq )
44 dupd <repeats> swap like ;