I tend to use variables a lot to improve readability but when it comes to monad, I came with my own convention to make it clear my variable is wrapped in a (possibly stack of) monad(s)
def getUser(id: Int): Future[User] = ???
val _user1 = getUser(1)
val _user2 = getUser(2)
for {
user1 <- _user1
user2 <- _user2
} yield (user1, user2)
some of my colleagues tend to prefer this syntax:
val fUser1 = getUser(1) // makes it clear user is wrapped in a Future
But I believe this could be error prone as :
// getUser now returns an option
def getUser(id: Int): Option[User]
val fUser1 = getUser(1) // still compiles but is misleading
// same, if getUser returns a Future[Either[String, User]]
val fUser1 = getUser(1) // fUser1 looks like a Future[User] to me
I think prefixing variables name by _ is the less worst solution but is not ideal either... Do you have a solution for that ?