strings.tables: faster format-table.
parent
646e9db251
commit
bdefd57819
|
@ -1,28 +1,22 @@
|
||||||
! Copyright (C) 2009, 2010 Slava Pestov.
|
! Copyright (C) 2009, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel sequences fry math.order splitting ;
|
USING: kernel sequences fry math.order math.ranges splitting ;
|
||||||
IN: strings.tables
|
IN: strings.tables
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: map-last ( seq quot -- seq )
|
|
||||||
[ dup length iota <reversed> ] dip '[ 0 = @ ] 2map ; inline
|
|
||||||
|
|
||||||
: max-length ( seq -- n )
|
: max-length ( seq -- n )
|
||||||
[ length ] [ max ] map-reduce ;
|
[ length ] [ max ] map-reduce ; inline
|
||||||
|
|
||||||
: format-row ( seq -- seq )
|
: format-row ( seq -- seq )
|
||||||
dup max-length
|
dup max-length '[ _ "" pad-tail ] map! ;
|
||||||
'[ _ "" pad-tail ] map ;
|
|
||||||
|
|
||||||
: format-column ( seq ? -- seq )
|
: format-column ( seq -- seq )
|
||||||
[
|
dup max-length '[ _ CHAR: \s pad-tail ] map! ;
|
||||||
dup max-length
|
|
||||||
'[ _ CHAR: \s pad-tail ] map
|
|
||||||
] unless ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: format-table ( table -- seq )
|
: format-table ( table -- seq )
|
||||||
[ [ string-lines ] map format-row flip ] map concat
|
[ [ string-lines ] map format-row flip ] map concat
|
||||||
flip [ format-column ] map-last flip [ " " join ] map ;
|
flip [ but-last-slice [ format-column ] map! drop ] keep
|
||||||
|
flip [ " " join ] map! ;
|
||||||
|
|
Loading…
Reference in New Issue