Hi! I found the following question by @johangwbass...
# arrow
a
Hi! I found the following question by @johangwbasson on Gitter and I'm interested to know the answer but its not answered yet! so I forwarded it here:
Good 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 appreciated
PS: I think it could be better if a link to this channel is added to Arrow-kt.io web site home page.
t
🙏 1
❤️ 1
a
Sorry! I haven't seen it! 😏