- Handling stacked monads and the like e.g.
List[Option[T]]
, `Future[Option[T]`` - Referentially transparent error handling
- Error accumulation/'parallel' validation
- Adding together
Option[T]
s (a la http://stackoverflow.com/a/16319667, not sure how to word this well) - More explicitly typesafe collections (e.g. non-empty, guarantee that list.head never throws, etc)
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 java.io.InputStream | |
import org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils | |
import org.apache.spark.sql.{ DataFrame, Row } | |
import org.postgresql.copy.CopyManager | |
import org.postgresql.core.BaseConnection | |
val jdbcUrl = s"jdbc:postgresql://..." // db credentials elided | |
val connectionProperties = { |
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
/** | |
* Intersperses words with spaces and trims ends, accounts for basic smilies. | |
*/ | |
def wordsToSentence(words: Vector[String]): String = { | |
val punctuation = Set(":", ";", ".", ",", "!", "?") | |
val smilies = Set(":)", ":(", ":<", ":}", ":|", ":o") | |
// @TODO really bad implementation probably, clean this up later | |
words.zipWithIndex.foldLeft("") { case (acc, (word, i)) => | |
val isLastWordPairSmilie = if (words.isDefinedAt(i - 1)) { |
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 akka.actor._ | |
object Server extends App { | |
val system = ActorSystem("serverSystem") | |
val serverActor = system.actorOf(Props(new ServerActor), name = "ServerActor") | |
} | |
class ServerActor extends Actor { | |
def receive = { | |
case message: String => |
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 akka.actor._ | |
object Client extends App { | |
val system = ActorSystem("clientSystem") | |
val clientActor = system.actorOf(Props(new ClientActor), name = "ClientActor") | |
clientActor ! SayHello | |
} | |
class ClientActor extends Actor { |
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
# 'client' conf | |
akka { | |
actor { | |
provider = "akka.remote.RemoteActorRefProvider" | |
} | |
remote { | |
enabled-transports = ["akka.remote.netty.tcp"] | |
netty.tcp { | |
hostname = "127.0.0.1" | |
port = 2553 |
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
libraryDependencies ++= Seq( | |
"com.typesafe.akka" %% "akka-actor" % "2.2.3", | |
"com.typesafe.akka" %% "akka-remote" % "2.2.3" | |
) |