I have a program which looks roughly like this
- Waits for some files
- When they arrive, parses them to extract data
- Reads database state
- Performs calculation
- Saves new state to database
- Generates emails on the basis of computed data
<?xml version="1.0" encoding="UTF-8"?> | |
<scheme name="oxbow" version="1" parent_scheme="Default"> | |
<option name="LINE_SPACING" value="1.0" /> | |
<option name="EDITOR_FONT_SIZE" value="12" /> | |
<option name="EDITOR_FONT_NAME" value="Consolas" /> | |
<colors /> | |
<attributes> | |
<option name="ABSTRACT_CLASS_NAME_ATTRIBUTES"> | |
<value> | |
<option name="FOREGROUND" value="666666" /> |
import java.sql.{Connection, SQLException} | |
import javax.sql.DataSource | |
import scalaz.zio.{IO, KleisliIO} | |
object Transactions { | |
sealed abstract class Isolation(private[Transactions] val i: Int) | |
object Isolation { | |
case object Serialized |
scala> (1 to 20).toList | |
res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) | |
//Simple side effects | |
scala> res1 take 3 foreach (i => println(i)) | |
1 | |
2 | |
3 | |
scala> res1 take 3 foreach println |
/** | |
* Part Zero : 10:15 Saturday Night | |
* | |
* (In which we will see how to let the type system help you handle failure)... | |
* | |
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0) | |
*/ | |
import scalaz._ | |
import Scalaz._ |
Welcome to Scala 2.12.3 (OpenJDK 64-Bit Server VM, Java 1.8.0_181). | |
Type in expressions for evaluation. Or try :help. | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
type TU = java.util.concurrent.TimeUnit | |
val NANOSECONDS: TU = java.util.concurrent.TimeUnit.NANOSECONDS | |
val MICROSECONDS: TU = java.util.concurrent.TimeUnit.MICROSECONDS | |
val MILLISECONDS: TU = java.util.concurrent.TimeUnit.MILLISECONDS |
Don't let anyone mislead you that there are no big changes. The big change is that fixes and security updates will no longer be provided to old versions of Java unless:
OpenJDK
and makes them availableHistorically OpenJDK
was quite separate from OracleJDK
. This is no longer the case. Oracle are basically providing two separate distributions of Java: OracleJDK
and OpenJDK
. They are meant to be technically equivalent, although it should be pretty obvious that OracleJDK
is likely to ship with add-on features aimed at enterprises (e.g. management tooling or better GC).
/////////////////////////////////////////////////////////////////////// | |
// You are supplied with the following interfaces/implementations | |
/////////////////////////////////////////////////////////////////////// | |
/** Interface representing the performing of a computation at some specific key */ | |
public interface Computation<K, V> { | |
K key(); | |
V compute(); | |
} |
Error:(117, 26) type mismatch; | |
found : akka.http.scaladsl.server.Route | |
(which expands to) akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult] | |
required: akka.stream.scaladsl.Flow[akka.http.scaladsl.model.HttpRequest,akka.http.scaladsl.model.HttpResponse,Any] | |
Http().bindAndHandle(route, thisHost, port) onComplete { | |
//where: | |
val route: Route = ??? |
//In scalaz 8 IO | |
IO.fail(new Error("1")) | |
.ensuring(IO.fail(new Error("2"))) | |
.ensuring(IO.fail(new Error("3"))) | |
.catchAll[E](e4 => IO.sync(println(e4.toString))) | |
//is (I think) equivalent to this? | |
try { | |
try { | |
try { |