import... | What it imports |
---|---|
cats.std.type |
Typeclass instances for standard library type (think List , Option ) |
cats.syntax.type |
“Enhanced” methods for type (.toRightXor etc) |
cats.data.type |
Imports a type not part of the standard library (think Xor , Kleisli ) and its typeclass instances |
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 net.liftweb.common._ | |
import net.liftweb.http.LiftRules._ | |
import net.liftweb.http.rest.RestHelper | |
import net.liftweb.http.{S, JsonResponse, LiftResponse, Req} | |
import net.liftweb.json.JsonDSL._ | |
import scala.concurrent.duration.Duration | |
object RateLimit { | |
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> trait Assoc[K] { type V ; val value: V } | |
defined trait Assoc | |
scala> def mkAssoc[V0](k: String, v: V0): Assoc[k.type] { type V = V0 } = | |
| new Assoc[k.type] { type V = V0 ; val value = v } | |
mkAssoc: [V0](k: String, v: V0)Assoc[k.type]{type V = V0} | |
scala> implicit def nameAssoc = mkAssoc("Name", "Mary") | |
nameAssoc: Assoc[String("Name")]{type V = String} |
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
object IfBrowserIs { | |
def ie9 = if(S.request.map(_.isIE9).openOr(false)) PassThru else ClearNodes | |
} |
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
// Define the following traits and companion object | |
// It's in Rapture Core (https://github.com/propensive/rapture-core) if you don't want to | |
trait LowPriorityDefaultsTo { implicit def fallback[T, S]: DefaultsTo[T, S] = null } | |
object DefaultsTo extends LowPriorityDefaultsTo { implicit def defaultDefaultsTo[T]: DefaultsTo[T, T] = null } | |
trait DefaultsTo[T, S] | |
// Then, assuming we want to specify a default for a type class like `Namer`, | |
case class Namer[T](name: String) |
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
object Nullable { | |
sealed trait NullableTag | |
type Nullable[A] = A with NullableTag | |
def nullAs[B]: Nullable[B] = | |
null.asInstanceOf[Nullable[B]] | |
implicit class ToNullable[A](val a: A) extends AnyVal { | |
def `?`: Nullable[A] = a.asInstanceOf[Nullable[A]] | |
} |
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
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration. | |
// | |
// First the unsafe standard Scala Enumeration ... | |
// | |
object ScalaEnumDemo extends App { | |
// Example from scala.Enumeration scaladoc. Terse ... | |
object WeekDay extends Enumeration { | |
type WeekDay = Value | |
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | |
} |
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 sbt._ | |
import scala.languageFeature._ | |
import org.scalajs.sbtplugin.ScalaJSPlugin | |
import ScalaJSPlugin.autoImport._ | |
object DependencyLib { | |
sealed trait HasDialect | |
sealed trait HasJvm extends HasDialect | |
sealed trait HasJs extends HasDialect |
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/bash | |
# author: [email protected] | |
WORKDING_DIR="${1-$HOME/.vim/bundle}" | |
GIT_DIR_ROOT="$HOME/Workspace/.gitrepo" | |
echo "Working on $WORKDING_DIR" | |
for i in `find "$WORKDING_DIR" -mindepth 1 -maxdepth 1 -type d`; do | |
REPO_NAME="${i##*/}" | |
export GIT_WORK_TREE="$WORKDING_DIR/$REPO_NAME" |
This is a proposal for a lightning talk at the Reactive 2016 conference.
NOTE: If you like this, star ⭐ the Gist - the amount of stars decides whether it makes the cut! You could also Retweet if you want :)
JavaScript is a dynamic language, and there's nothing wrong with that. It allows quick iteration and lowers barriers. However, sometimes some compile-time type checking is just what you need to keep your code in line and give yourself the confidence to build bigger and faster. Flow gives the best of both worlds. You can have normal JavaScript but you can also add types where they're helpful, and it adds zero cost at runtime. In this talk I'll show Flow as it applies to a Redux & React codebase.
OlderNewer