Skip to content

Instantly share code, notes, and snippets.

@franklinchou
franklinchou / gist:9d27a92c3cb9537146a16ffe1ba55799
Created November 23, 2018 00:23 — forked from milessabin/gist:9042788
Boilerplate free conversion from case classes to shapeless records via LabelledGeneric ... coming soon to shapeless 2.0.0.
scala> import shapeless._, record._
import shapeless._
import record._
scala> case class Person(name: String, address: String, age: Int)
defined class Person
scala> val joe = Person("Joe", "Brighton", 33)
joe: Person = Person(Joe,Brighton,33)
@franklinchou
franklinchou / Type_Families_Sealed_Traits_and_Exhaustive_Pattern_Matching_in_Scala.md A brief lesson on Type Families, Sealed Traits, and Exhaustive Pattern Matching in Scala

Scala: Type Families, Sealed Traits, and Exhaustive Pattern Matching

By: Matt Barackman

What is a Type Family?

A collection of objects or case classes that share a sealed trait.

In the example below, the type family would be a collection of traffic light colors with Red, Yellow, and Green as member objects.

@franklinchou
franklinchou / recurse.py
Created July 8, 2018 01:36
Example of "bubble up" recursion
def traverse_backward():
def recurse(i):
if i == 0:
return
recurse(i - 1)
print(i)
recurse(5)
def traverse_forward():
"""
"Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of
the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five
print "FizzBuzz".
"""
if __name__ == "__main__":
for index in range(1, 100 + 1):
if (index % 3 == 0):
print("Fizz")
@franklinchou
franklinchou / try.scala
Created October 31, 2017 14:12
Getting try/catch to work in Scala
import java.time.LocalDate
import java.time.TemporalAdjusters
import scala.util.{Success, Failure, Try}
import org.scalatest.FunSpec
/**
* Check if date passed is the last day of the month.
*/