]> gitweb.factorcode.org Git - factor.git/blob - extra/sequences/rotated/rotated.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / extra / sequences / rotated / rotated.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: accessors kernel math sequences ;
4 IN: sequences.rotated
5
6 TUPLE: rotated
7 { seq read-only }
8 { n integer read-only } ;
9
10 C: <rotated> rotated
11
12 M: rotated length seq>> length ;
13
14 M: rotated virtual@
15     [ n>> + ] [ seq>> ] bi [
16         length over 0 < [ + ] [
17             2dup >= [ - ] [ drop ] if
18         ] if
19     ] keep ;
20
21 M: rotated virtual-exemplar seq>> ;
22
23 INSTANCE: rotated virtual-sequence
24
25 : all-rotations ( seq -- seq' )
26     dup length <iota> [ <rotated> ] with map ;