- Install autocomplete-plus and autocomplete-snippets plugins
- Add these snippets to your snippets.cson
- Try typing
u
and the LaTeX name of the symbol you want and you should get autocompletetion with a preview of the symbol
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 AllExamples extends App { | |
import shapeless._ | |
final class All[L <: HList](val values: L) { | |
def apply[A](implicit selector: Selector[L, A]): A = values.select[A] | |
} | |
object All { | |
// package a value of type A, convertible to type B, into an HList containing just B |
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 org.catch22.amazonws | |
/** | |
* This class derives from https://github.com/keplar/scalapac | |
* It's released under the Apache licence V2.0 | |
* Copyright (c) 2012 Orderly Ltd. All rights reserved. | |
* Copyright (c) 2012 Mark Lister | |
* | |
*/ |
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
/** Constructing "singleton types" from compile-time literals | |
* | |
* val x = Example.foo(42) | |
* val y: x.T = 42 // compiles | |
* val z: x.T = 43 // doesn't | |
* | |
*/ | |
package s | |
import scala.language.experimental.macros |
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 Ok { | |
trait Foo[A] | |
case class Bar(x: Int) | |
object Bar { | |
implicit class BarOps(bar: Foo[Bar]) { | |
val ok = "ok" | |
} | |
} | |
def usage(bar: Foo[Bar]) = bar.ok // Ok, the implicit conversion is found in the Bar companion object |
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
/* A better way to tag types? | |
* | |
* 1) object Time: here we are distinguishing between different uses of a Long, | |
* yet there is no boxing whatsoever. | |
* | |
* main calls start: ()J | |
* main calls timed: (Function0, J) | |
* Function0 gives up the result: ()J | |
* timed calls now: ()J | |
* timed calls elapsed$extension: (JJ)J |
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._; import SingletonTypes._; import Record._ | |
import shapeless._ | |
import SingletonTypes._ | |
import Record._ | |
scala> val r = ("foo" ->> 23) :: ("bar" ->> true) :: ("baz" ->> 2.0) :: HNil | |
r: (String("foo"), Int) :: (String("bar"), Boolean) :: (String("baz"), Double) :: HNil = | |
(foo,23) :: (bar,true) :: (baz,2.0) :: HNil | |
scala> r.head // r is an HList of pairs of singleton-typed Strings and values ... |
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 List[+T] | |
case class Cons[T](hd: T, tl: List[T]) extends List[T] | |
sealed trait Nil extends List[Nothing] | |
case object Nil extends Nil | |
trait Show[T] { | |
def apply(t: T): 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
scala> import scala.language.experimental.macros | |
import scala.language.experimental.macros | |
scala> import scala.reflect.macros.{ Context, TypecheckException } | |
import scala.reflect.macros.{Context, TypecheckException} | |
scala> object NoncompilationTests { | |
| def compiles(code: _): Boolean = macro compiles_impl | |
| def compiles_impl(c: Context)(code: c.Tree) = c.literal( | |
| try { |
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 DynamoReader { | |
def typeReader[A](f: (JsObject => JsResult[A])) = new Reads[A] { | |
def reads(json: JsValue): JsResult[A] = json match { | |
case obj: JsObject => f(obj) | |
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("error.expected.jsobject")))) | |
} | |
} | |
} | |
object DynamoString { |
OlderNewer