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.language.higherKinds | |
trait SomeLike[+A] { | |
def value: A | |
} | |
trait OptionSig { | |
type Option[+_] | |
type Some[+A] <: Option[A] with SomeLike[A] | |
type None <: Option[Nothing] |
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 combos(numDice: Int, sides: Int): List[List[Int]] = { | |
if (numDice > 0) { | |
for { | |
h <- (1 to sides).toList | |
t <- combos(numDice - 1, sides) | |
} yield { | |
h :: t | |
} | |
} else { | |
List(Nil) |
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 algebra.benchmark | |
import org.openjdk.jmh.annotations.Benchmark | |
import org.openjdk.jmh.annotations.Param | |
import org.openjdk.jmh.annotations.Scope | |
import org.openjdk.jmh.annotations.Setup | |
import org.openjdk.jmh.annotations.State | |
import org.openjdk.jmh.annotations.{ Fork, Warmup, Measurement } | |
@Warmup(iterations = 5) |
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 Point2[@mb A] { | |
def x: A | |
def y: A | |
... | |
} | |
case class IntPoint2(x: Int, y: Int) extends Point2[Int] | |
case class DoublePoint2(x: Double, y: Double) extends Point2[Double] | |
case class GenPoint2[A](x: A, y: A) extends Point2[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
resolvers += "Pellucid Bintray" at "http://dl.bintray.com/pellucid/maven" | |
libraryDependencies += "com.pellucid" %% "framian" % "0.3.3" |
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 example | |
import argonaut._ | |
import Argonaut._ | |
sealed trait WidgetType | |
object WidgetType { | |
case object Sprocket extends WidgetType | |
case object Cog extends WidgetType | |
case object Doowazzle extends WidgetType |
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
// This prints the top 10 alternative bases, ordered by the (# of factors, excluding 1 & base) / base. | |
// So, the last number printed has the highest number of factors relative to the size of the base. | |
// | |
// Turns out that 12 is a great base! | |
object Main extends App { | |
// 7560 is the smallest number that is divisible by all number between 1 and 10. | |
val facMap = (1 to 7560).foldLeft(Map.empty[List[Int], Int]) { (acc, n) => | |
val factors = (2 to (n / 2)).filter(n % _ == 0).toList | |
if (acc contains factors) acc | |
else acc + (factors -> n) |
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
/** | |
* Something similar to Kleisli[Future, A, B], but doesn't require an | |
* ExecutionContext up front. | |
*/ | |
case class AsyncFn[A, B](fn: ExecutionContext => A => Future[B]) { | |
def map[B0](f: B => B0): AsyncFn[A, B0] = | |
AsyncFn[A, B0] { implicit ec => a => | |
fn(ec)(a).map(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
{ | |
a = "abc" | |
xyz { | |
x = 1 | |
y = "xyz" | |
z = 2.3 | |
} | |
} |