- What is your go-to snack?
- What's one thing you know better than anyone on the team?
- If your safety was guaranteed, would you rather explore deep space or the oceans?
- If you had to give a 10 minute presentation with zero prep time, what would you present?
- What's a music album that is so good that you shouldn't skip a single track?
- If you have a friend coming into town for the weekend and you could only guarantee doing one thing, what thing would you recommend?
- What is your favorite kind of pie?
- What is your favorite dinosaur?
- What animal best represents you?
- If you had to recommend one book to read, what book would you recommend?
// Generate numbers from -10 .. 100 | |
var numbers = Enumerable.Range(-10, 111); | |
// Determines all positive numbers that are divisible by 6 | |
var positiveDivisbleBySix = numbers | |
.Where(x=>x > 0) // iterates through the whole list (111 comparisons, returning 100 results) | |
.Where(x=>x % 2 == 0) // iterates through the new list (100 comparisons, returning 50 results) | |
.Where(x=>x % 3 == 0); // iterates through the new list (50 comparisons, returning 16 results) | |
// Overall metrics: 261 comparisons over 111 total elements) |
const _ = require("lodash"); | |
const items = [ | |
{id:1, name: "fluffy", animal: "cat"}, | |
{id: 2, name: "spot", animal: "dog"}, | |
{id: 3, name: "clifford", animal: "dog"}, | |
{id: 4, name: "tony", animal: "tiger"} | |
]; | |
const isAnimal = (animal, item) => item.animal === animal; |
Learning Functional Programming Through Construction: First Principles
In the past five years, functional programming has increased dramatically in popularity which has lead to an explosion of resources in learning these concepts. But, between languages (Haskell, Elm, PureScript, F#), libraries (Ramda, fp-ts), and concepts (Monads, Monoids, Functors), it can be overwhelming in determining where to start and how to begin.
In this talk, I'm going to show you three fundamental concepts of functional programming: pure functions, immutability, and composition by not only explanation, but through building these concepts through code and application. As we explore each concept, I'll show you the advantages of following these principles, how they will improve your development experience, and how they will set the stage for more advanced ideas.
Intended for those who have experience with TypeScript or C#, by the end of this presentation, you will understand how pure functions lead to easier to test code, how imm
using System; | |
using System.IO.Compression; | |
using System.Text; | |
public class InMemoryZipCompresser | |
{ | |
public byte[] Compress (string fileContents) | |
{ | |
using (var ms = new MemoryStream()) | |
{ |
Func<int, string> fizzBuzz = i => | |
{ | |
if (i % 5 == 0 && i % 3 == 0) return "FizzBuzz"; | |
else if (i % 3 == 0) return "Fizz"; | |
else if (i % 5 == 0) return "Buzz"; | |
return i.ToString(); | |
}; | |
Func<StringBuilder, string, StringBuilder> reduce = (sb, s) => sb.AppendLine(s); |
import qualified Data.List (sort) | |
data Person = Person Bool | |
instance Show Person where | |
show (Person b) = show b | |
printPerson :: Person -> IO () | |
printPerson person = putStrLn (show person) | |
data Mood = Blah | Woot deriving (Show, Eq) |
data TisAnInteger = TisAn Integer | |
instance Eq TisAnInteger where | |
(==) (TisAn a) (TisAn b) = a == b | |
data TwoIntegers = Two Integer Integer | |
instance Eq TwoIntegers where | |
(==) (Two a b) (Two c d) = (a == c) && (b == d) | |
data StringOrInt = TisAnInt Int | TisAString String | |
instance Eq StringOrInt where |
public static class FunctionExtensions | |
{ | |
public static Func<T2> Apply<T1, T2>(this Func<T1, T2> func, T1 input) => () => func(input); | |
public static Func<T2, T3> Apply<T1, T2, T3>(this Func<T1, T2, T3> func, T1 input) => x => func(input, x); | |
public static Func<T2, T3, T4> Apply<T1, T2, T3, T4>(this Func<T1, T2, T3, T4> func, T1 input) => | |
(a, b) => func(input, a, b); | |
public static Action Apply<T1>(this Action<T1> action, T1 input) => () => action(input); | |
public static Action<T2> Apply<T1, T2>(this Action<T1, T2> action, T1 input) => a => action(input, a); |
// Learn more about F# at http://fsharp.org | |
open System | |
type Record = {x:int; y:int} | |
type Nested = {number:int; record:Record} | |
[<EntryPoint>] | |
let main argv = | |
let record = {x=10; y=20} | |
printfn "Creating a record with x=%i and y=%i" record.x record.y |