This file contains 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 models | |
import scala.util.matching.Regex | |
// Deps | |
object Types { | |
type Tag = String | |
} | |
import Types._ |
This file contains 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
#!/bin/sh | |
DOWNLOAD_DIR="$HOME/Downloads/weather" | |
REGION=txgulf | |
die() { | |
ec=$1 | |
shift | |
echo $@ >&2 | |
exit $ec |
This file contains 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
// Given this definition, | |
def buildWrites[U, T <: DataTyped[U]](baseWrites: Writes[T])(implicit typeToJs: U => Json.JsValueWrapper): Writes[T] | |
// Works! | |
val someWrites: Writes[SomeDataTyped_v1] = DataTyped.buildWrites[FeedEntryTypes.Value, SomeDataTyped_v1](Json.writes[SomeDataTyped_v1]) | |
// Fails. | |
val someWrites: Writes[SomeDataTyped_v1] = DataTyped.buildWrites(Json.writes[SomeDataTyped_v1]) | |
[error] .../DataSpec.scala:65: type mismatch; |
This file contains 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 countdown(a): | |
for i in a: | |
print a - i | |
if i == 3: | |
print "blast off!" | |
break | |
i+=1 | |
countdown(3): |
This file contains 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 split[A, B](f: A => A => C)(x: A): C = f(x)(x) | |
def swap[A, B, C](f: A => B => C): B => A => C = (b: B) => (a: A) => f(a)(b) | |
def filter[A](as: List[A])(f: A => Boolean): List[A] = foldRight2(as, List.empty[A])(uncurried[A, List[A], List[A]](split(f andThen (if(_) (Cons.apply[A] _).curried else swap(const[List[A], A] _))) _)) | |
def filterAnnotated[A](as: List[A])(f: A => Boolean): List[A] = { | |
val prepend: A => List[A] => List[A] = (Cons.apply[A] _).curried | |
val ignore: A => List[A] => List[A] = swap(const[List[A], A] _) | |
val getApply: A => A => List[A] => List[A] = f andThen (if(_) prepend else ignore) |
This file contains 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 shapeless._ | |
sealed trait Animal | |
case class Point(x: Double, y: Double) | |
case class Color(r: Byte, g: Byte, b: Byte) | |
case class Turtle(position: Point, heading: Double, color: Color) extends Animal | |
case class Cat(position: Point, color: Color) extends Animal | |
implicit val turtlePosition = lens[Turtle].position | |
implicit val catPosition = lens[Cat].position |
This file contains 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 shapeless._ | |
import shapeless.labelled.KeyTag | |
import shapeless.record._ | |
import shapeless.ops.hlist.ToList | |
import shapeless.ops.record.{ Keys, Values } | |
import shapeless.syntax.singleton._ | |
import utils.ExtendedPostgresDriver.simple._ | |
object slickless { |
This file contains 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 shapeless._ | |
case class Location(lat: Double, lon: Double) | |
case class User(id: Long, username: String, location: Location) | |
case class Car(id: Long, location: Location) | |
object ImplicitLenses extends App { | |
implicit val userLocationLens: Lens[User, Location] = { | |
val ret = lens[User].location | |
ret |
This file contains 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
... | |
type FirstName = (String @@ FirstName.Internal) | |
object FirstName { trait Internal; def apply(value: String): FirstName = value.asInstanceOf[FirstName] } | |
type LastName = (String @@ LastName.Internal) | |
object LastName { trait Internal; def apply(value: String): LastName = value.asInstanceOf[LastName] } | |
type Email = (String @@ Email.Internal) | |
object Email { trait Internal; def apply(value: String): Email = value.asInstanceOf[Email] } | |
... |
This file contains 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 shapeless.tag | |
import shapeless.tag | |
scala> trait FirstName | |
defined trait FirstName | |
scala> val FirstName = tag[FirstName] | |
FirstName: shapeless.tag.Tagger[FirstName] = shapeless.tag$Tagger@779a0926 | |
scala> trait LastName |
OlderNewer