alilosoft
10/12/2019, 12:08 PMGood day. I'm new to functional programming and the arrow library and was wondering if anybody can help me.
I was wondering how one handles resources like database pools or connections and how you pass them to a function. For instance: Let say I have an authenticate method:
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:
fun authenticate(con: Connection, username: String, password: String) ....
fun getUserByUsername(con: Connection, username: String): Option<User> ...
What is the best practice when it comes to functional programming?
Also from what I have read and if my understanding is correct, this is impure and normally IO would be used?
fun getUserByUsername(username: String): IO<Option<User>>
Is this correct? Any help appreciatedPS: I think it could be better if a link to this channel is added to Arrow-kt.io web site home page.
thanh
10/12/2019, 12:14 PMalilosoft
10/12/2019, 12:46 PM