]> gitweb.factorcode.org Git - factor.git/commitdiff
add more db.utils
authorDoug Coleman <erg@jobim.local>
Thu, 16 Apr 2009 20:19:05 +0000 (15:19 -0500)
committerDoug Coleman <erg@jobim.local>
Thu, 16 Apr 2009 20:19:05 +0000 (15:19 -0500)
extra/db2/utils/utils.factor

index 71fa9bc5ae97d34946275f47ac515754156ae1bb..0557593209c1a735c7618563562133a2f81a8bec 100644 (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 ;