// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/interpreter/SyncDbInterpreter.java
// public class SyncDbInterpreter
// {
//     private final Try0<Connection, SQLException> ds;
// 
//     /**
//      * Construct an interpreter, given a piece of code which knows how to spawn connections, e.g. a Data Source, Connection Pool,
//      * Driver Manager, etc.
//      * @param ds - the data source, which can spawn connections
//      */
//     public SyncDbInterpreter(Try0<Connection, SQLException> ds)
//     {
//         this.ds = ds;
//     }
// 
//     /**
//      * Attempt to run this operation and return its result
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A submit(DB<A> doOp)
//     {
//         try (Connection c = ds.f())
//         {
//             return doOp.run(c);
//         }
//         catch (SQLException e)
//         {
//             throw new RuntimeException(e);
//         }
// 
//     }
// 
//     /**
//      * Attempt to run this operation and return its result. The operation is run transactionally - i.e. if any error is
//      * encountered, the operation is rolled back.
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A transact(DB<A> doOp)
//     {
// 
//         return submit(transactional(doOp));
// 
//     }
// }
// 
// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/ops/DbOps.java
// public static <A, C1 extends Iterable<A>, C2 extends Iterable<A>> DB<C2> sequence(Iterable<DB<A>> xs,
//         CanBuildFrom<A, C1, C2> cbf)
// {
//     DB<C1> acc = DB.unit(cbf.createBuffer());
//     for (DB<A> db : xs)
//     {
//         DB<C1> fAcc = acc;
//         acc = db.bind(x -> fAcc.map(ys -> cbf.add(x, ys)));
//     }
// 
//     return acc.map(cbf::build);
// }


import com.novarto.sanedbc.core.interpreter.SyncDbInterpreter;
import fj.control.db.DB;
import fj.data.List;
import org.junit.Test;
import java.sql.DriverManager;
import static com.novarto.sanedbc.core.ops.DbOps.sequence;
import static fj.data.List.arrayList;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
package com.novarto.sanedbc.examples;




public class SequenceExample
{
    @Test
    public void testIt()
    {
        SyncDbInterpreter dbi = new SyncDbInterpreter(
                () -> DriverManager.getConnection("jdbc:hsqldb:mem:test", "sa", "")
        );

        //given an iterable of DB's
        List<DB<String>> dbList = arrayList(
                DB.unit("foo"),
                DB.unit("bar"),
                DB.unit("baz")
        );

        //we can treat it as a DB<List>
// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/interpreter/SyncDbInterpreter.java
// public class SyncDbInterpreter
// {
//     private final Try0<Connection, SQLException> ds;
// 
//     /**
//      * Construct an interpreter, given a piece of code which knows how to spawn connections, e.g. a Data Source, Connection Pool,
//      * Driver Manager, etc.
//      * @param ds - the data source, which can spawn connections
//      */
//     public SyncDbInterpreter(Try0<Connection, SQLException> ds)
//     {
//         this.ds = ds;
//     }
// 
//     /**
//      * Attempt to run this operation and return its result
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A submit(DB<A> doOp)
//     {
//         try (Connection c = ds.f())
//         {
//             return doOp.run(c);
//         }
//         catch (SQLException e)
//         {
//             throw new RuntimeException(e);
//         }
// 
//     }
// 
//     /**
//      * Attempt to run this operation and return its result. The operation is run transactionally - i.e. if any error is
//      * encountered, the operation is rolled back.
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A transact(DB<A> doOp)
//     {
// 
//         return submit(transactional(doOp));
// 
//     }
// }
// 
// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/ops/DbOps.java
// public static <A, C1 extends Iterable<A>, C2 extends Iterable<A>> DB<C2> sequence(Iterable<DB<A>> xs,
//         CanBuildFrom<A, C1, C2> cbf)
// {
//     DB<C1> acc = DB.unit(cbf.createBuffer());
//     for (DB<A> db : xs)
//     {
//         DB<C1> fAcc = acc;
//         acc = db.bind(x -> fAcc.map(ys -> cbf.add(x, ys)));
//     }
// 
//     return acc.map(cbf::build);
// }


// Path: sane-dbc-examples/src/test/java/com/novarto/sanedbc/examples/SequenceExample.java
import com.novarto.sanedbc.core.interpreter.SyncDbInterpreter;
import fj.control.db.DB;
import fj.data.List;
import org.junit.Test;
import java.sql.DriverManager;
import static com.novarto.sanedbc.core.ops.DbOps.sequence;
import static fj.data.List.arrayList;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

package com.novarto.sanedbc.examples;




public class SequenceExample
{
    @Test
    public void testIt()
    {
        SyncDbInterpreter dbi = new SyncDbInterpreter(
                () -> DriverManager.getConnection("jdbc:hsqldb:mem:test", "sa", "")
        );

        //given an iterable of DB's
        List<DB<String>> dbList = arrayList(
                DB.unit("foo"),
                DB.unit("bar"),
                DB.unit("baz")
        );

        //we can treat it as a DB<List>
        DB<List<String>> db = sequence(dbList);