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
trait Future[+T] extends Awaitable[T] { | |
def flatMap[S](f: T => Future[S])(implicit executor: ExecutionContext): Future[S] = { | |
import impl.Promise.DefaultPromise | |
val p = new DefaultPromise[S]() | |
onComplete { | |
case f: Failure[_] => p complete f.asInstanceOf[Failure[S]] | |
case Success(v) => try f(v) match { | |
// If possible, link DefaultPromises to avoid space leaks | |
case dp: DefaultPromise[_] => dp.asInstanceOf[DefaultPromise[S]].linkRootOf(p) | |
case fut => fut.onComplete(p.complete)(internalExecutor) |
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
trait Future[+T] { | |
def flatMap[S](f: T => Future[S]) | |
(implicit executor: ExecutionContext): Future[S] = { | |
val promise = new Promise[S]() | |
this.onComplete { | |
// The first Future (this) failed |
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
package com.example.basic | |
import java.util.Properties | |
import org.apache.kafka.clients.producer.{Callback, RecordMetadata, ProducerRecord, KafkaProducer} | |
import scala.concurrent.Promise | |
case class BasicProducer(topic: String, brokerList:String, sync: Boolean) { | |
val kafkaProps = new Properties() |
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
package com.example.basic | |
import java.util.Properties | |
import kafka.consumer.{ConsumerIterator, Consumer, ConsumerConfig, KafkaStream} | |
import kafka.serializer.StringDecoder | |
import kafka.utils.VerifiableProperties | |
case class BasicConsumer(zooKeeper: String, groupId: String, waitTime: String) { | |
val kafkaProps = new Properties() |
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
def factorial(n: Int): Int = if (n == 0) 1 else n * factorial(n - 1) | |
factorial(4) = | |
if (4 == 0) 1 else 4 * factorial(4 - 1) = | |
4 * factorial(4 - 1) = | |
4 * factorial(3) = | |
4 * { if (3 == 0) 1 else 3 * factorial(3 - 1) } = | |
4 * { 3 * factorial(3 - 1) } = | |
4 * { 3 * factorial(2) } = |
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
def factorial(n: Int) : Int = { | |
def factorialTR(acc: Int, n: Int) : Int = if (n == 1) acc else factorialTR(acc * n, n - 1) | |
factorialTR(1, n) | |
} | |
factorial(4) = | |
factorialTR(1, 4) = | |
if (4 == 1) 1 else factorialTR(1 * 4, 4 - 1) = | |
factorialTR(1 * 4, 4 - 1) = |
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
def f1(x: Int): Int = x*x | |
val f2 = (x: Int) => x*x | |
def f3 = (x: Int) => x*x | |
def f4:(Int => Int) = x => x*x |
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
trait A { | |
def foo(text: String) = printf("a says:" + text) | |
} | |
trait B extends A { | |
override def foo(text: String) = printf("b says:" + text) | |
} | |
trait C extends A { | |
override def foo(text: String) = printf("c says:" + text) |
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
package com.angieslist.common.play.controller | |
import com.angieslist.common.http.DispatchHttpClientComponent | |
import com.angieslist.common.{Logger, LoggerComponent} | |
import com.ning.http.client.FluentCaseInsensitiveStringsMap | |
import com.typesafe.config.{Config, ConfigFactory} | |
import dispatch.{url, _} | |
import play.api.mvc._ | |
import scala.collection.JavaConversions._ |
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
def counter(file: String) = { | |
scala.io.Source.fromFile(file) | |
.getLines | |
.flatMap(_.split("\\W+")) | |
.foldLeft(Map.empty[String, Int]){ | |
(count, word) => count + (word -> (count.getOrElse(word, 0) + 1)) | |
} | |
} |