Skip to content

Instantly share code, notes, and snippets.

View oxbowlakes's full-sized avatar

Christopher Marshall oxbowlakes

View GitHub Profile
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 = ???
class CsvUpdateParser(val header: String, val rows: Stream[String], val delimiter: String) extends CsvParser[(TxnId, ListedTransactionUpdateBuilder)] {
protected override def parse(line: String): Failure \/ (TxnId, ListedTransactionUpdateBuilder) = {
val cols = splitIgnoreQuotes(line, delimiter)
var a = 0
for {
txnId <- tokenAt("Txn ID", cols).map(_.toLong)
ccy <- tokenAt("Sett Ccy", cols).map(parseCcy)
rate <- tokenAt("Sett FX", cols).map(parseBigDecimal)
settDate <- tokenAt("Sett Date", cols).map(x => parseAccountingDate(x, "yyyy-MM-dd"))
state <- tokenAt("State", cols).map(x => if (x.isEmpty) null else EventState.valueOf(x))

You have a single Java codebase in one repo to put all your code in. The code ultimately runs about 30 services/batch jobs (call these end points, or EPs). Some EPs share literally no code with others. All in all, we have well over 250 kloc compiled in one go to produce a single artefact (a jar, let's call it LEVIATHAN)

Each time a change is committed, the code is built and a new LEVIATHAN artefact version is emitted - hundreds of them, thousands even. There is a database where each EP is associated with the version of the code which should run it.

Stable EPs can thus be hundreds of versions behind current. Let's say that you need to update such a stable EP by adding some new feature. You are then in a position of having to bring EP "foobar" up from v1.2.3 of LEVIATHAN to v8.9.10. You have absolutely no idea whether code that Foobar depends on has changed problematically in this space.

I'm not in any way saying that this is a sensible way of organising a monorepo and I'm sure there are plenty of legitimat

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global
scala> scala.concurrent.Future( { println("foo"); 4 })
foo
res0: scala.concurrent.Future[Int] = Success(4)
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - IntelliJ IDEA 2016.1.3 Build #IC-145.1617.8
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - JDK: 1.8.0_45
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - VM: Java HotSpot(TM) 64-Bit Server VM
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - Vendor: Oracle Corporation
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - OS: Windows 7
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - Last Action: EditorEnter
2016-07-12 14:11:53,537 [104621175] ERROR - m.intellij.util.ExecutorsQuery - null
kotlin.KotlinNullPointerException
at org.jetbrains.kotlin.types.StarProjectionImplKt.starProjectionType(StarProjectionImpl.kt:48)
at org.jetbrains.kotlin.types.StarProjectionImpl$_type$2.invoke(StarProjectionImpl.kt:31)
import java.util.Optional;
import java.util.function.Function;
class Main {
public static void main(String[] args) {
Optional<String> o = Optional.of("foo");
Function<String, String> f = s -> null;
Function<String, String> g = String::valueOf;
//lawless lolz
import java.util.stream.*;
import java.util.function.*;
class FMTS {
public static void main(String[] args) {
IntStream intStream1 = IntStream.of(1, 2);
IntStream intStream2 = IntStream.of(1, 2);
//FlatMap
object Unchecked extends App {
class Foo[A] {
def doIt(o: Any): Option[A] = Some(o.asInstanceOf[A])
}
println(new Foo[String].doIt(3))
}
/* compile it */
//scalac Unchecked.scala
import java.util.*;
class Unchecked {
static class Foo<A> {
Optional<A> doIt(Object o) { return Optional.of((A) o);}
}
public static void main(String[] args) {
System.out.println(new Foo<String>().doIt(3));
}
}
scala> val it = Traversable(1); it foreach (i => println(s"$i and ${it.isEmpty}"))
1 and false
scala> val it = Iterator(1); it foreach (i => println(s"$i and ${it.isEmpty}"))
1 and true