• Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Examples of simple Scala Macros

Essential Macros Code Examples

Copyright 2014 Dave Gurnell of Underscore http://underscore.io

These example projects are companion material for the Underscore Essential Scala Macros course as well as for the author's talk, Macros for the Rest of Us, presented at ScalaDays 2014.

Licensed under the Apache License v2.0 http://www.apache.org/licenses/LICENSE-2.0.html

If you're interested in this content, sign up to our mailing list at http://underscore.io where we post updates and code samples about Scala, Scala Macros, and functional programming in general.

The Examples

Each example is split into two projects, app and lib. lib defines the macros and app makes use of them.

  • hello - Hello world written as a macro. The macro embeds a compilation timestamp in the printed message to demonstrate that it is executed at compile time. This is contrasted with regular code that prints a timestamp at run time.

  • maximum - Simple project demonstrating basic setup. The macro itself, maximum, isn't particularly useful, but the project serves as a good example of the various concepts in play.

  • printtree - Macro that uses showCode and showRaw to print the desugared syntax and underlying tree structure of arbitrary snippets of Scala code. Good for doing research in advance of writing new macros.

  • simpleassert - Macro demonstrating simple pattern matching on trees using quasiquotes. Slightly improved version of Scala's built-in assert method that prints various values involved in the assertion.

  • betterassert - Macro demonstrating more advanced tree inspection using pattern matching and tree traversal. Improved version of simpleassert that prints useful debugging information in a much wider range of cases.

  • printtype - Family of generic macros that print a variety of information about their type parameters.

  • orderings - Code generation macro that inspects a type and creates an object allowing sorting by any of its fields. This technique is useful when writing, for example, a web service that allows users to sort a database by any field in the returned data.

  • enumerations - Generating the set of instances of a sealed trait. Useful for rolling your own enumerations via sealed case objects.

  • whitebox - Simple project demonstrating the fundamental difference between whitebox and blackbox macros. See comments in the main application file for details.

  • validation - Sketch of a codebase for a validation library that automatically tags errors using the names of the erroneous fields. One significant property is that the macro is implemented as a chainable method call rather than as a top-level function.

  • csv - Sketch of a type-class-based codebase for CSV serialization. An implicit macro is used to support automatic materialization of type class instances for case classes.

More Repositories

1

shapeless-guide

The Type Astronaut's Guide to Shapeless
TeX
760
star
2

slickless

Support for shapeless HLists/Generics in Slick.
Scala
164
star
3

shapeless-guide-code

Example code to accompany shapeless-guide.
Scala
133
star
4

essential-scala

Source code for Underscore's Essential Scala
Scala
118
star
5

essential-slick-code

Source Code for the examples in Essential Slick
Scala
83
star
6

compose

Compositional music composition using Scala, SuperCollider, and Web Audio.
Scala
76
star
7

advanced-scala-code

Code examples for Underscore's Advanced Scala course
Scala
54
star
8

essential-interpreters

Patterns for building interpreters in Scala
Scala
50
star
9

scalax15-slick

Slick workshop for Scala Exchange 2015
Scala
45
star
10

essential-slick

Essential Slick Pandoc Source
TeX
38
star
11

underscore-ebook-template

Template for Underscore eBooks
CoffeeScript
29
star
12

scalax15-interpreters

Source code for the Interpreters workshop at Scala Exchange 2015.
Scala
28
star
13

creative-scala-template

Template for those following Creative Scala
Scala
22
star
14

csvside

CSV reader and writer combinators for Scala. Made with Cats.
Scala
21
star
15

eescala

20
star
16

essential-scala-code

Exercises and examples for the Essential Scala training course.
Scala
20
star
17

essential-play-code

Exercises and solutions for Underscore's Essential Play
Scala
17
star
18

essential-scala-doodle-case-study

The Doodle case study supplement to Essential Scala
Scala
17
star
19

philosopher-emoji

Philosopher emoji for all your online metaphysical needs.
14
star
20

free-objects-code

Code samples accompanying the Essential Scalaz supplement dealing with free monoids and free monads.
Scala
12
star
21

books

HTML
10
star
22

scalaxhack-2016

Topic and project suggestions for ScalaxHack 2016.
9
star
23

doodlebot

An Essential Scala case study using Finch and Scala.js
JavaScript
9
star
24

numeric-vc

Derives instances of Numeric for value classes
Scala
7
star
25

eescala-code

Scala
7
star
26

essential-speaking

Slides and notes on speaking at tech conferences.
6
star
27

essential-scala-exercises

Exercises for Essential Scala (replaces essential-scala-code)
Scala
6
star
28

annihilator

Example implementation of Annihilator type class
Scala
5
star
29

interpreters-and-you

Scala
5
star
30

essential-play

Essential Play
Shell
5
star
31

http4s-example

An example using http4s
Scala
4
star
32

essential-interpreters-code

Code samples from Essential Interpreters
Scala
4
star
33

rtb

Example of real-time bidding engine (for training purposes)
Scala
3
star
34

remarkjs-template

Remarkjs Presentation Template, with Underscore Branding
HTML
3
star
35

essential-slick-workshop

Introductory Slick workshop (slides and code samples).
Scala
3
star
36

chatbot

Online chat with http4s and FS2
Scala
2
star
37

jobby

Automating conversion of jobs spreadsheet data into markdown
Scala
1
star
38

underscoreio

Underscore web site and blog.
HTML
1
star
39

linter-explorer

An extremely brief example of WartRemover and Scapegoat. Two scala linters
Scala
1
star
40

scala-start

Quick start for Scala
Shell
1
star
41

wejo-autumn-2019

Wejo Autumn 2019
Scala
1
star
42

csv-workshop

Functional programming workshop exploring the magical domain of CSV parsing.
Scala
1
star
43

formless

A form / questionnaire library, analogous to Google Forms, with http4s and Finch backends
Scala
1
star