Good day. I'm new to functional programming and th...
# arrow
j
Good day. I'm new to functional programming and the arrow library and was wondering of anybody can help me. I was wondering how one handle resources like database pools or connections and how you pass them to a function. For instance: Let say I have an authenticate method:
Copy code
fun authenticate(username: String, password: String): Either<Error, Token> {
        // validation etc ..
        val user = getUserByUsername(username)
    }

    fun getUserByUsername(username: String): Option<User> {
        // JDBC Query for user
        val rs = con.prepareStatement("SELECT * FROM user .....")
        ....
        val user = mapRowToUser(rs) // etc
        return Option.fromNullable(user)
    }
My question is do I pass in the connection of database pool as a parameter like so:
Copy code
fun authenticate(con: Connection, username: String, password: String) ....
    fun getUserByUsername(con: Connection, username: String): Option<User>  ...
What is best practise when it comes to functional programming? Also from what I have read and if my undersyanding is correct, this is inpure and normally IO would be used?
Copy code
fun getUserByUsername(username: String): IO<Option<User>>
Is this correct? Any help appreciated
🤔 1