Permalink
Browse files

[enhance] stdlib, database: Added some utils for generic dbset

  • Loading branch information...
1 parent fa8caff commit 1a4fc8a1e2a779f734a4f3655487d0a8b0c04b63 @BourgerieQuentin BourgerieQuentin committed Mar 5, 2012
Showing with 20 additions and 3 deletions.
  1. +20 −3 stdlib/core/db/dbset.opa
@@ -9,8 +9,25 @@ package stdlib.core.db
@opacapi type dbset('a, 'engine) = DbSet.t('a, 'engine)
DbSet = {{
- fold(init, dbset:dbset(_, _))(f) =
- Iter.fold(acc, e -> f(e, acc), dbset.iter, init)
+ @package build(iter, engine) = ~{iter engine}
+
+ fold(init, dbset:dbset(_, _))(f) =
+ Iter.fold(acc, e -> f(e, acc), dbset.iter, init)
+
+ iterator(dbset:dbset('a, _)):iter('a) = dbset.iter
+
+ @stringifier(dbset('a, _)) to_string(fa, _, dbset) =
+ tx = Text.cons("Database Set:\n")
+ (_, tx) = fold((0, tx), dbset)((i, tx), a ->
+ tx = Text.insert_right(tx, " {i}")
+ |> Text.insert_right(_, " : ")
+ |> Text.insert_right(_, fa(a))
+ |> Text.insert_right(_, ",\n")
+ (i+1, tx)
+ )
+ Text.to_string(tx)
- iterator(dbset:dbset('a, _)):iter('a) = dbset.iter
}}
+
+
+@opacapi DbSet_genbuild = DbSet.build

0 comments on commit 1a4fc8a

Please sign in to comment.