add more db.utils

db4
Doug Coleman 2009-04-16 15:19:05 -05:00
parent 840675e242
commit f9afd71369
1 changed files with 19 additions and 1 deletions
extra/db2/utils

View File

@ -1,14 +1,32 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel math math.parser strings ;
USING: arrays kernel math math.parser strings sequences
words ;
IN: db2.utils
: ?when ( object quot -- object' ) dupd when ; inline
: ?1array ( obj -- array ) dup string? [ 1array ] when ; inline
: ??1array ( obj -- array/f ) [ ?1array ] ?when ; inline
: ?first ( sequence -- object/f ) 0 ?nth ;
: ?second ( sequence -- object/f ) 1 ?nth ;
: ?first2 ( sequence -- object1/f object2/f )
[ ?first ] [ ?second ] bi ;
: assoc-with ( object sequence quot -- obj curry )
swapd [ [ -rot ] dip call ] 2curry ; inline
: ?number>string ( n/string -- string )
dup number? [ number>string ] when ;
ERROR: no-accessor name ;
: lookup-accessor ( string -- accessor )
dup ">>" append "accessors" lookup
[ nip ] [ no-accessor ] if* ;
ERROR: string-expected object ;
: ensure-string ( object -- string )
dup string? [ string-expected ] unless ;