FAQ Database Discussion Community


Scala - Futures and Eithers

scala,dictionary,future,either
this thread gave me an idea how to structure my code: Scala-way to handle conditions in for-comprehensions? The part in question: // First create the JSON val resultFuture: Future[Either[Failure, JsResult]] = for { userRes <- userDao.findUser(userId) user <- userRes.withFailure(UserNotFound).right authRes <- userDao.authenticate(user) auth <- authRes.withFailure(NotAuthenticated).right goodRes <- goodDao.findGood(goodId) good <-...

How do I program monadicaly in Java8 while getting comparable performance?

java,performance,java-8,monads,either
Is monadic programming in Java 8 slower? Below is my test (a right-biased Either is used that creates new instances for each computation). The imperative version is 1000 times faster. How do I program monadicaly in Java8 while getting comparable performance? Main.java public class Main { public static void main(String...

Regex Challenge - either … or

php,regex,match,either
I havent been able to figure this one out. I need to match all those strings by matching whole and its surroundings underscores (in one regex statement): whole_anything anything_whole anything_whole_anything but it must NOT match this anythingwholeanything anything_wholeanything anythingwhole_anything That means... make a regex statement, that match phrase whole only...

How can I make analog of Either?

scala,generics,covariance,either
Compiler complains at Left(e): Expression of type Left(List[ServiceError, Nothing]) doesn't conform to expected type Either[E , R] sealed trait ServiceResult[+E <: List[ServiceError], +R ] { def toEither: Either[E , R] = this match { case Success(a) => Right(a) case Failure(e) => **Left(e)** } } final case class Success[+R](a: R) extends...