Skip to content

Instantly share code, notes, and snippets.

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@tonymorris
tonymorris / RngPerson.scala
Last active December 14, 2015 16:29
Demonstration of pure-functional random generation using the free monad. Person is a recursive product type. The program prints a random value of the type Person.
package com.nicta
package rng
import scalaz._, Scalaz._, effect._
// A data type representing a person.
// We are going to produce random instances.
// Note that this data type is recursive.
// The `children` field holds 0 or many Person instances.
case class Person(name: String, age: Int, surname: Option[String], children: List[Person])
@jboner
jboner / latency.txt
Last active May 27, 2024 05:44
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD