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 whatever | |
| import com.typesafe.config.{ Config, ConfigFactory, ConfigObject, ConfigValue } | |
| import org.joda.time.DateTime | |
| trait Factory[A] { | |
| def create(c: Configuration): A | |
| } | |
| /** |
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
| object Loan { | |
| trait Close[A] { | |
| def close(a: A): Unit | |
| } | |
| object Close { | |
| private def closeQ[A: Close](a: A): Boolean = | |
| try { implicitly[Close[A]].close(a); true } | |
| catch { case _: Exception => false } | |
| implicit def Tuple2Close[A: Close, B: Close] = new Close[(A, B)] { |
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
| // ------------------------------------------------------------------------------------------------- | |
| // Framework | |
| // ------------------------------------------------------------------------------------------------- | |
| /** Simple typeclass for turning Strings into things */ | |
| trait Mapper[A] extends (String => A) | |
| /** define all the Mapper typeclass instances and generators we need */ | |
| object Mapper { | |
| implicit val StringMapper = new Mapper[String] { | |
| def apply(s: String) = s |
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
| final case class Schrödinger[+A, +B](private a: => A, private b: => B) extends Either[A, B] { | |
| private lazy val actual : Either[A, B] = | |
| if (new Random().nextBoolean()) | |
| Left(a) | |
| else | |
| Right(b) | |
| def isLeft = actual.isLeft | |
| def isRight = actual.isRight | |
| def left = actual.left |
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
| object Maps { | |
| import scalaz._, syntax.semigroup._ | |
| def unionWithKey[A, K](f: (K, A, A) => A): (Map[K, A], Map[K, A]) => Map[K, A] = | |
| (m1, m2) => | |
| (m1 -- m2.keySet) ++ m2.map { | |
| case (k, v) => k -> (m1 get k map { f(k, v, _) } getOrElse v) | |
| } | |
| def unionWith[K, A: Semigroup]: (Map[K, A], Map[K, A]) => Map[K, A] = |
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 java.util.Map; | |
| import java.util.Map.Entry; | |
| import com.google.common.collect.ImmutableMap; | |
| import com.google.common.collect.ImmutableMap.Builder; | |
| import com.google.common.collect.MapDifference; | |
| import com.google.common.collect.MapDifference.ValueDifference; | |
| import com.google.common.collect.Maps; | |
| public final class Maps { |
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 scalaz.{ Monoid, Monad, Comonad, Traverse, Applicative } | |
| import com.twitter.util._ | |
| trait FutureInstances { | |
| implicit def futureMonoid[A](implicit A: Monoid[A]) = new Monoid[Future[A]] { | |
| override def zero: Future[A] = Future(A.zero) | |
| override def append(f1: Future[A], f2: => Future[A]): Future[A] = |
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
| /** the original Deferred (similar to jQuery) based implementation with lots of mutation */ | |
| public Promise<MyData> getMyDataAsync(String id) { | |
| // create a new Deferred instance to represent this operation | |
| final Deferred<MyData> deferred = Deferred.create(); | |
| // perform an async operation to get mydata, typically with a lower-level async api | |
| rawDataClient.get(id) | |
| // handle success case | |
| .done(new Effect<Map<String, Object>>() { | |
| public void handle(Map<String, Object> value) { | |
| // convert the result into the target type and resolve the deferred |
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.fayi.ftp | |
| object CSVParser { | |
| val ADDRESS = "ftp://mirrors.kernel.org/gnu/README.DESCRIPTIONS" | |
| val ADDRESS2 = "ftp://ftp.gnu.org/README" | |
| def main(args: Array[String]) { | |
| def parse(s: Stream[String]) = { | |
| val cells = (_: String).split(",") |
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 Higher[F[_]] | |
| trait Box[A] | |
| object Box { | |
| implicit def HigherBox = new Higher[Box] {} | |
| } | |
| object Foo { | |
| val box = implicitly[Higher[Box]] // compiles fine !!! |