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
scalaVersion := "2.11.7" | |
crossScalaVersions := Seq("2.9.2", "2.10.5", "2.11.7") | |
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo"))) | |
def conditionalSettings[P](conditionalKey: SettingKey[P])(predicate: P => Boolean): Seq[Def.Setting[_]] = { | |
// How can I make this suck less? | |
Seq( | |
publishArtifact := { if(predicate(conditionalKey.value)) false else publishArtifact.value }, | |
publishLocal := { if(predicate(conditionalKey.value)) {} else publishLocal.value }, |
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 done = "GIT R DONE!!!" | |
done: String = GIT R DONE!!! | |
scala> object git { | |
| def r(s: String): Unit = println(s) | |
| } | |
defined object git | |
scala> git r done | |
GIT R DONE!!! |
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 UnapplySyntax { | |
trait Unapplier[A, B] { def unapply(a: A): Option[B] } | |
class <= [B, A](f: A => Option[B]) extends Unapplier[A, B] { | |
def unapply(a: A): Option[B] = f(a) | |
} | |
object <= { | |
def apply[B, A](f: A => Option[B]): B <= A = new <=(f) | |
} |
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 reorderLocally[I](f: I => Long, range:Long):Process1[I, I] = { // TODO: Can we replace Long with something like A: Order ? | |
import scala.collection.immutable.SortedMap | |
def emitMapValues(m: SortedMap[Long, Vector[I]]) = | |
emitAll(m.foldLeft(Vector.empty[I]) { case (acc, (_, tss)) => acc ++ tss }) | |
def go(buffered: SortedMap[Long, Vector[I]]): Process1[I, I] = { | |
receive1Or[I, I](emitMapValues(buffered)) { t => | |
val until = f(t) - range | |
val (toEmit, toBuffer) = buffered span { case (x, _) => x <= until } |
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 mergeSorted[F[_], I, A: Order](sourceLeft: Process[F, I], sourceRight: Process[F, I])(f: I => A): Process[F, I] = { | |
mergeSorted(sourceLeft, f)(sourceRight, f).flatMap { | |
case Both(a, b) => Process.emit(a) ++ Process.emit(b) | |
case This(a) => Process.emit(a) | |
case That(b) => Process.emit(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
import scalaz.stream.Process._ | |
import scalaz.stream._ | |
import tee._ | |
object ChunkWhen { | |
def chunkWhen[I](f: (I, I) => Boolean): Process1[I, Vector[I]] = { | |
def go(acc: Vector[I]): Process1[I,Vector[I]] = | |
receive1Or[I, Vector[I]](emit(acc)){ i => | |
acc.lastOption match { | |
case Some(last) if ! f(last, i) => emit(acc) ++ go(Vector(i)) |
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.joescii | |
import org.scalacheck._ | |
import Gen._ | |
import Prop._ | |
object PalindromeChecks extends Properties("palindrome") { | |
val randBoolean:Gen[Boolean] = for { | |
b <- choose(0,1) | |
} yield { |
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.joescii.sbtjs | |
import com.gargoylesoftware.htmlunit. { BrowserVersion => HUBrowserVersion } | |
import HUBrowserVersion._ | |
sealed trait Browser | |
object Browsers extends Browsers | |
trait Browsers { | |
case object Firefox38 extends Browser |
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.joescii | |
package object code { | |
val DbThing = new DbThingImpl() | |
val HttpThing = new HttpThingImpl() | |
val BizThing = new BizThingImpl(DbThing, HttpThing) | |
trait DbThing { | |
def getDbStuff(params):Future[DbStuff] | |
} |
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> import scala.collection.immutable.ListMap | |
import scala.collection.immutable.ListMap | |
scala> val m = ListMap("a" -> "1", "b" -> "2", "c" -> "3", "d" -> "4", "e" -> "5") | |
m: scala.collection.immutable.ListMap[String,String] = Map(a -> 1, b -> 2, c -> 3, d -> 4, e -> 5) | |
scala> val ks = m.keys.toList | |
ks: List[String] = List(a, b, c, d, e) | |
scala> val upper = m.keys.map(_.toUpperCase).toList |
NewerOlder