// 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));
// 
//     }
// }


import com.novarto.lang.Collections;
import com.novarto.sanedbc.core.interpreter.SyncDbInterpreter;
import fj.P2;
import fj.control.db.DB;
import fj.data.Tree;
import org.junit.Test;
import java.sql.DriverManager;
import java.util.List;
import java.util.Map;
import static fj.P.p;
import static fj.data.List.arrayList;
import static fj.data.Tree.leaf;
import static fj.data.Tree.node;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
        //the final result is an immutable data structure.
        //the intermediate representation was an implementation detail, which is not observable outside this method.
        //this technique is dubbed "Effectively immutable"

        return result;

    }

    private <A> Tree<A> toTree(A root, Map<A, ? extends Iterable<A>> map)
    {
        Iterable<A> theseChildren = map.get(root);
        if (theseChildren == null || Collections.isEmpty(theseChildren))
        {
            return leaf(root);
        }

        fj.data.List.Buffer<Tree<A>> childNodes = fj.data.List.Buffer.empty();
        for (A child : theseChildren)
        {
            childNodes = childNodes.snoc(toTree(child, map));
        }

        return node(root, childNodes.toList());
    }


    @Test
    public void testIt()
    {

// 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-examples/src/test/java/com/novarto/sanedbc/examples/EffectivelyImmutable.java
import com.novarto.lang.Collections;
import com.novarto.sanedbc.core.interpreter.SyncDbInterpreter;
import fj.P2;
import fj.control.db.DB;
import fj.data.Tree;
import org.junit.Test;
import java.sql.DriverManager;
import java.util.List;
import java.util.Map;
import static fj.P.p;
import static fj.data.List.arrayList;
import static fj.data.Tree.leaf;
import static fj.data.Tree.node;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

        //the final result is an immutable data structure.
        //the intermediate representation was an implementation detail, which is not observable outside this method.
        //this technique is dubbed "Effectively immutable"

        return result;

    }

    private <A> Tree<A> toTree(A root, Map<A, ? extends Iterable<A>> map)
    {
        Iterable<A> theseChildren = map.get(root);
        if (theseChildren == null || Collections.isEmpty(theseChildren))
        {
            return leaf(root);
        }

        fj.data.List.Buffer<Tree<A>> childNodes = fj.data.List.Buffer.empty();
        for (A child : theseChildren)
        {
            childNodes = childNodes.snoc(toTree(child, map));
        }

        return node(root, childNodes.toList());
    }


    @Test
    public void testIt()
    {

        SyncDbInterpreter dbi = new SyncDbInterpreter(