Skip to content

Instantly share code, notes, and snippets.

View tjheslin1's full-sized avatar

Thomas Heslin tjheslin1

  • London
View GitHub Profile
resource "aws_iam_role" "lambda-exec-role" {
name = "lambda-exec-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {

Keybase proof

I hereby claim:

  • I am tjheslin1 on github.
  • I am tjheslin1 (https://keybase.io/tjheslin1) on keybase.
  • I have a public key ASCK0pCahopQCftx0gwQWPrfID4yXNWKMlWq4NMDz2UOOwo

To claim this, I am signing this object:

def doThing(implicit ec: ExecutionContext) =

Can be replaced by:

type EC[_] = ExecutionContext

and

trait T
// defined trait T
case class A() extends T
// defined class A
case class B(a: A) extends T
// defined class B
def check[Y <: T](t: T): Boolean = t.isInstanceOf[Y]

Taken from scala-with-cats by Noel Welsh and Dave Gurnell

Definition of a Monad

  • pure, of type A => F[A]

pure abstracts over constructors, providing a way to create a new monadic context from a plain value.

  • flatMap, of type (F[A], A => F[B]) => F[B]

Taken from scala-with-cats by Noel Welsh and Dave Gurnell

A monoid for a type B is:

  • an operation combine with type (B, B) => B
  • an element empty of type B
trait Monoid[B] {
 def combine(x: B, y: B): B
passwords:
bobsDatabase: oracle
alicesDatabase: oracle

Taken from Essential Scala by Noel Welsh and Dave Gurnell

The type class pattern separates the implementation of functionality from the type the functionality is provided for.

In Scala, a type class is just a trait.

trait ExampleTypeClass[A] {
  def doSomething(in: A): Foo
}
// Taken from Essential Scala by Noel Welsh and Dave Gurnell
for {
a <- getFirstNumber // getFirstNumber returns Option[Int]
b <- getSecondNumber // getSecondNumber returns Option[Int]
} yield a + b
// The final result is an Option[Int]---the result of
// applying `+` to `a` and `b` if both values are present
// Taken from Essential Scala by Noel Welsh and Dave Gurnell
// fold: structural recursion
sealed trait LinkedList[A] {
def fold[B](end: B)(pair: (A, B) => B): B =
this match {
case End() => end
case Pair(hd, tl) => pair(hd, tl.fold(end, pair))
}
}