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
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
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
// 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
// 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 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
#!/bin/bash | |
# author: janlay@gmail.com | |
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 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
// Alternative to sealed abstract case class pattern for Scala 2.12.2+ | |
// Benefits: | |
// - 1 final class instead of 1 sealed class + anonymous subclass | |
// - portable to Scala 3 regardless of opaque types | |
// - less boilerplate | |
final case class Angle private (toDegrees: Int) { | |
// Define our own `copy` method to suppress synthetic one | |
// Add private to prevent it from being used | |
def copy(degrees: Int = toDegrees): Angle = Angle.fromDegrees(degrees) |
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]] | |
} |
OlderNewer