1 ! Copyright (C) 2020 John Benediktsson
2 ! See https://factorcode.org/license.txt for BSD license
3 USING: accessors kernel math math.order sequences sequences.private ;
7 { underlying sequence read-only }
8 { length integer read-only }
9 { elt object read-only } ;
11 TUPLE: padded-head < padded ;
12 TUPLE: padded-tail < padded ;
14 C: <padded-head> padded-head
15 C: <padded-tail> padded-tail
18 [ underlying>> length ] [ length>> ] bi max ;
20 M: padded-head nth-unsafe
21 [ [ length>> ] [ underlying>> ] bi [ length [-] - ] keep ] keep
22 2over bounds-check? [ drop nth-unsafe ] [ 2nip elt>> ] if ;
24 M: padded-tail nth-unsafe
25 [ underlying>> ] keep 2over bounds-check?
26 [ drop nth-unsafe ] [ 2nip elt>> ] if ;
28 INSTANCE: padded immutable-sequence