This file contains hidden or 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.collection.JavaConverters._ | |
// you can write to stdout for debugging purposes, e.g. | |
// println("this is a debug message") | |
object Task1Solution { | |
def phoneMetric(number: Int): Long = { | |
val numberStr = number.toString | |
100000000000L * numberStr.size + |
This file contains hidden or 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.annotation.tailrec | |
import scala.collection.JavaConverters._ | |
// you can write to stdout for debugging purposes, e.g. | |
// println("this is a debug message") | |
object Task2Solution { | |
class TransformationIterator(s: String, removable: String) extends Iterator[String] { | |
var i = 0 | |
val remLen = removable.length |
This file contains hidden or 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
require 'zlib' | |
APACHE_LINE_RX = /^([0-9\.]+)\s+\S+\s+\S+\s+\[[^\]]+\]\s+\"[^\"]+\"\s+(\d+)\s+(\d+).*$/ | |
def parse_apache_line(text_line) | |
if text_line =~ APACHE_LINE_RX | |
{:ip => $1, :bytes => $3.to_i} | |
else | |
nil | |
end | |
end |
This file contains hidden or 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.slick.lifted.CanBeQueryCondition | |
// optionally filter on a column with a supplied predicate | |
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) { | |
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = { | |
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this) | |
} | |
} | |
// example use case | |
import java.sql.Date |
This file contains hidden or 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
sealed trait ContextDescription { | |
def value: String | |
} | |
final case class EmailContext(value: String) extends ContextDescription | |
final case class MobileContext(value: String) extends ContextDescription | |
// ... | |
Seq(EmailContext(email), MobileContext(mobile)). | |
filter(_.value.nonEmpty). | |
map( context => | |
LocalPersonContext( |
This file contains hidden or 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
scala> val kidsNames = List("John", "George", "Victor") | |
kidsNames: List[String] = List(John, George, Victor) | |
scala> val beatlesNames = List("John", "Ringo", "Paul", "George") | |
beatlesNames: List[String] = List(John, Ringo, Paul, George) | |
scala> kidsNames.intersect(beatlesNames) | |
res2: List[String] = List(John, George) | |
// Looks reasonable! |