factor/basis/strings/tables/tables.factor

22 lines
581 B
Factor
Raw Normal View History

2010-01-14 10:10:13 -05:00
! Copyright (C) 2009, 2010 Slava Pestov.
2009-01-26 03:21:28 -05:00
! See http://factorcode.org/license.txt for BSD license.
2012-07-13 21:42:34 -04:00
USING: kernel sequences fry math.order math.ranges splitting ;
2009-01-26 03:21:28 -05:00
IN: strings.tables
<PRIVATE
2010-02-02 05:48:30 -05:00
: format-row ( seq -- seq )
dup longest length '[ _ "" pad-tail ] map! ;
2012-07-13 21:42:34 -04:00
: format-column ( seq -- seq )
dup longest length '[ _ CHAR: \s pad-tail ] map! ;
2009-01-26 03:21:28 -05:00
PRIVATE>
: format-table ( table -- seq )
[ [ string-lines ] map format-row flip ] map concat flip
[ { } ] [
[ but-last-slice [ format-column ] map! drop ] keep
flip [ " " join ] map!
] if-empty ;