This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package model | |
import org.scalatest.matchers.should.Matchers | |
import org.scalatest.wordspec.AsyncWordSpecLike | |
import java.text.SimpleDateFormat | |
import java.time.Instant | |
import java.util.Date | |
import java.util.concurrent.{ExecutorService, Executors} | |
import scala.concurrent.{Future, Promise} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package model | |
import org.scalatest.matchers.should.Matchers | |
import org.scalatest.wordspec.AsyncWordSpecLike | |
import java.text.SimpleDateFormat | |
import java.time.Instant | |
import java.util.Date | |
import java.util.concurrent.{ExecutorService, Executors} | |
import scala.concurrent.{Future, Promise} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sum the elements of a list | |
def sum(list: List[Int]): Int = list match { | |
case Nil => 0 | |
case head :: tail => head + sum(tail) | |
} | |
//Reverse a list | |
def reverse[A](list: List[A]): List[A] = list match { | |
case Nil => Nil | |
case head :: Nil => List(head) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"leader": "akka://Catalog-Domain@10.0.10.47:2551", | |
"members": [{ | |
"node": "akka://Catalog-Domain@10.0.31.10:2551", | |
"nodeUid": "6963894071647843575", | |
"roles": [ | |
"dc-default" | |
], | |
"status": "Leaving" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"time": "2020-02-12T18:34:22.487Z", | |
"message": "Slf4jLogger started" | |
}, | |
{ | |
"time": "2020-02-12T18:34:23.587Z", | |
"message": "Remoting started with transport [Artery tcp]; listening on address [akka://Catalog-Domain@10.0.75.227:2551] with UID [-4725893541386128209]" | |
}, | |
{ | |
"time": "2020-02-12T18:34:23.614Z", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.concurrent.{ExecutionContext, Future} | |
case class Post() // For sake of simplicity it hasn't attributes | |
def findPostsForUser(userId: Long): Future[List[Post]] = ??? | |
def postsByUsers(userIds: List[Long])(implicit ec: ExecutionContext) = | |
for { | |
aUserId <- userIds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sequence[A,B](seq: Seq[Either[A,B]]): Either[Seq[A], B] = seq.foldLeft(Left(Seq.empty[A]): Either[Seq[A], B]){ | |
(acc, e) => e match { | |
case Left(exception) => acc.left.map(l => l :+ exception) | |
case Right(_) => acc | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate[A](sequence: Seq[A])(f: A => Either[Exception,A]): Seq[Either[Exception,A]] = sequence.map(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List[Match] process(String csv) throws CSVMatchConstraintException{ | |
List[String] rows = toRows(csv); | |
validator.validate(rows) //in case of invalid it will throw an exeption | |
return rows.stream() | |
.map(row => new Match(row(0), row(1), row(2), row(3))) | |
.collect(toList()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CSVMatchConstraintException extends RuntimeException { | |
public CSVMatchConstraintException(Int lineNumber, Throwable err) { | |
super("Error at line " + lineNumber, err) | |
} | |
} |
NewerOlder