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 language.experimental.macros | |
| import language.implicitConversions | |
| import scala.reflect.macros._ | |
| // We are going to provide a custom error message for when users use the wrong variant of some | |
| // type, `Foo`. Note that `Foo` needs to be invariant or contravariant in its type parameter! | |
| case class Foo[T]() | |
| object Foo { | |
| implicit def reportError[T, U](value: Foo[T]): Foo[U] = macro Macros.reportErrorMacro[T, U] | |
| } |
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
| Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| // Import the Rapture modules we need | |
| scala> import rapture._, uri._, codec._, io._, fs._, core._, csv._ | |
| import rapture._ | |
| import uri._ | |
| import codec._ | |
| import io._ |
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
| Welcome to Scala version 2.11.5 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| // Define a `Parser` typeclass. This must be invariant. | |
| scala> trait Parser[T] { def parse(s: String): Option[T] } | |
| defined trait Parser | |
| // Here are a couple of typeclass instances to show it working | |
| scala> implicit val identityParser = new Parser[String] { def parse(s: String) = Some(s) } |
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
| Welcome to Scala version 2.10.5 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> import rapture.core._ | |
| import rapture.core._ | |
| scala> val str: String = alloc() // new String() | |
| str: String = "" |
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
| My company, Sygneca Ltd., has an opening for a Web application | |
| developer, and of course our primary development language is Scala. | |
| About us: | |
| We are a small technology solutions provider targetting SMBs, based in | |
| Basingstoke, England. We primarily develop web-based systems, such as | |
| bespoke ecommerce and content-managed websites, and are also expanding | |
| into other areas, such as business automation. Our website is at |
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
| scala> import rapture.i18n._ | |
| import rapture.i18n._ | |
| scala> import languages._ | |
| import languages._ | |
| // This would typically be a runtime value, but we'll just use "FR" as a fixed example | |
| scala> val localeString = "FR" | |
| localeString: String = FR |
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 rapture.json._, jsonBackends.spray._ | |
| import rapture.io._ | |
| import rapture.fs._ | |
| import rapture.uri._ | |
| import rapture.codec._, encodings.`UTF-8`._ | |
| val json = Json.parse(uri"file:///home/work/test.json".slurp[Char]) | |
| case class AddressComponent(short_name: String, long_name: String) | |
| val components = json.result.address_components.as[List[AddressComponent]] |
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
| > sbt package | |
| [info] Loading global plugins from /home/jpretty/.sbt/0.13/plugins | |
| [info] Loading project definition from /home/jpretty/dev/github.com/ensime-server/project | |
| [info] Set current project to ensime (in build file:/home/jpretty/dev/github.com/ensime-server/) | |
| [info] Formatting 1 Scala source {file:/home/jpretty/dev/github.com/ensime-server/}jerk(compile) ... | |
| [info] Formatting 41 Scala sources {file:/home/jpretty/dev/github.com/ensime-server/}server(compile) ... | |
| [info] Formatting 7 Scala sources {file:/home/jpretty/dev/github.com/ensime-server/}swank(compile) ... | |
| [info] Formatting 18 Scala sources {file:/home/jpretty/dev/github.com/ensime-server/}sexpress(compile) ... | |
| [info] Formatting 5 Scala sources {file:/home/jpretty/dev/github.com/ensime-server/}api(compile) ... | |
| [info] Formatting 2 Scala sources {file:/home/jpretty/dev/github.com/ensime-server/}spray-json-shapeless(compile) ... |
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
| Welcome to Scala version 2.10.5 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| // We're using returnResult mode, so that methods return `Result`s instead of throwing exceptions | |
| scala> import rapture.core._, modes.returnResult._ | |
| import rapture.core._ | |
| import modes.returnResult._ | |
| // Our LaTeX backend of choice is xelatex |
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
| // Example usages: | |
| // Returns true | |
| checkTypeMismatch { | |
| import deferTypeErrors._ | |
| 7: String | |
| } | |
| // Returns false | |
| checkTypeMismatch { |