Skip to content

Instantly share code, notes, and snippets.

View jdegoes's full-sized avatar

John A. De Goes jdegoes

View GitHub Profile

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
@jdegoes
jdegoes / die-flags-die.md
Created October 8, 2014 17:20
Death to Boolean Flags

Refactoring Booleans to Functions

Boolean parameters are a plague, responsible for non-composable, monolithic functions that never quite do enough, and countless programming bugs:

  • "Oops, meant to pass that as the 2nd boolean flag, not the 1st!"
  • "Oops, accidentally inverted the meaning of that boolean in the implementation!"
  • "Oops, the function isn't flexible enough for my use case, let's add a 6th boolean flag!"
  • "Oops, got the meaning of that boolean flag wrong, time to dig into the source code!"

All boolean parameters should be refactored into functions that effect the change otherwise encoded in the parameter.

SPEAKER ENGAGEMENT AGREEMENT V1.1

This Speaker Engagement Agreement ("Agreement") is made and entered into by and between ____________________ ("Speaker"), whose principal place of residence is __________________________________, and ____________________ ("Organizer"), whose primary mailing address is __________________________________, on ___________ ("Effective Date").

WHEREAS, the Speaker has knowledge, experience, and skills of interest to Organizer, and has been invited by the Organizer to present a talk at ____________________ ("Conference"), held on ___________ ("Conference Dates"); and

WHEREAS, the Organizer desires to have Speaker present a talk to an audience invited by Organizer, and the Speaker, to present this talk to said audience, and to other audiences across the Internet;

@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()

Introduction to the Rust Programming Language

Rust is a systems programming language designed for safety, concurrency, and performance. It has gained popularity for its innovative features that prevent memory-related bugs and allow for low-latency, performant, and efficient computation. Understanding Rust can provide new perspectives and approaches to building robust, concurrent, and high-performance applications.

In this 3-day workshop, attendees will receive a beginner-level introduction to Rust. By the end of the course, all participants, regardless of background, will have a solid entry-level foundation in Rust and be able to confidently use it for various real-world programming tasks.

NOTE: Although no familiarity with Scala is required, special attention will be given to the similarities and differences between Scala and Rust.

Who Should Attend

@jdegoes
jdegoes / Zippable.scala
Created March 17, 2021 20:36
Compositional zipping
package spartans.zipped
object Zipped {
sealed trait Zippable[-A, -B] {
type Out
def zip(left: A, right: B): Out
}
object Zippable extends ZippableLowPriority {
type Out[-A, -B, C] = Zippable[A, B] { type Out = C }
@jdegoes
jdegoes / zio-test.scala
Last active January 6, 2023 14:08
Simple example of testing with ZIO environment
object test {
import scalaz.zio._
type UserID = String
case class UserProfile(name: String)
// The database module:
trait Database {
val database: Database.Service
package net.degoes.zio
trait Sql {
type ColumnName
type TableName
sealed trait Table[+A]
/**
* (SELECT *, "foo", table.a + table.b AS sum... FROM table WHERE cond) UNION (SELECT ... FROM table)
package spartan.training
object TheMonadProblem {
sealed trait Parser[+A] { self =>
def map[B](f: A => B): Parser[B] = self.flatMap(a => Parser.succeed(f(a)))
def flatMap[B](f: A => Parser[B]): Parser[B] = Parser.FlatMap(self, f)
}
object Parser {
def succeed[A](a: A): Parser[A] = Succeed(a)
import zio._
sealed trait Config[+A] { self =>
def ++ [B](that: Config[B])(implicit zippable: Zippable[A, B]): Config[zippable.Out] =
Config.Zipped[A, B, zippable.Out](self, that, zippable)
def || [A1 >: A](that: Config[A1]): Config[A1] = Config.Fallback(self, that)
def ?? (label: String): Config[A] = Config.Labelled(self, label)