1 ! Copyright (C) 2020 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: accessors arrays kernel math math.order sequences
8 { underlying sequence read-only }
9 { length integer read-only }
10 { elt object read-only } ;
12 TUPLE: padded-head < padded ;
13 TUPLE: padded-tail < padded ;
15 C: <padded-head> padded-head
16 C: <padded-tail> padded-tail
19 [ underlying>> length ] [ length>> ] bi max ;
21 M: padded-head nth-unsafe
22 [ [ length>> ] [ underlying>> ] bi [ length [-] - ] keep ] keep
23 2over bounds-check? [ drop nth-unsafe ] [ 2nip elt>> ] if ;
25 M: padded-tail nth-unsafe
26 [ underlying>> ] keep 2over bounds-check?
27 [ drop nth-unsafe ] [ 2nip elt>> ] if ;
29 INSTANCE: padded immutable-sequence