combinators - lightning talk

23
Combinators Mike Harris

Upload: mike-harris

Post on 12-Apr-2017

59 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Combinators - Lightning Talk

CombinatorsMike Harris

Page 2: Combinators - Lightning Talk

How to Add Data Without Stopping Flow?

CSV Filter AddFile ID

Page 3: Combinators - Lightning Talk

How to Add Data Without Stopping Flow? (LINQ)

CSV Filter AddFile ID

read Where ???

C#

Page 4: Combinators - Lightning Talk

How to Add Data Without Stopping Flow? (LINQ)

CSV Filter AddFile ID

read Where ???

C#

Page 5: Combinators - Lightning Talk

How to Add Data Without Stopping Flow?K combinator

CSV Filter Add File ID

read Where Pipe

C#

Page 6: Combinators - Lightning Talk

MoreLINQ’s Pipe

public static IEnumerable<T> Pipe<T>( this IEnumerable<T> source, Action<T> action )

C#

Page 7: Combinators - Lightning Talk

MoreLINQ’s Pipe in Context

csv.GetRecords<TTarget>() .Where(x => x.PricingDate != "") .Pipe(x => { x.FileId = fileId; }) …

C#

Page 8: Combinators - Lightning Talk

Combinators

Page 9: Combinators - Lightning Talk

K combinator

let K x y = x

F#

Page 10: Combinators - Lightning Talk

K combinator

const tap = f => x => {f(x); return x;}; const K = tap;

JS

Page 11: Combinators - Lightning Talk

I combinator

let I x = x

F#

Page 12: Combinators - Lightning Talk

I combinator

const identity = x => x; const I = identity;

JS

Page 13: Combinators - Lightning Talk

S combinator

let S x y z = x z (y z)

F#

Page 14: Combinators - Lightning Talk

S combinator

const seq = function(/*funcs*/) { const funcs = Array.prototype.slice.call(arguments); return x => funcs.forEach(f => f(x)); }; const S = seq;

JS

Page 15: Combinators - Lightning Talk

Example

Page 16: Combinators - Lightning Talk

I = SKK

I = SKK

logic

Page 17: Combinators - Lightning Talk

I = SKK

I x = SKK x

definitions • I x = x • K xy = x • S xyz = xz(yz) logic

Page 18: Combinators - Lightning Talk

I = SKK

I x = SKK x = Kx (Kx)

definitions • I x = x • K xy = x • S xyz = xz(yz) logic

Page 19: Combinators - Lightning Talk

I = SKK

I x = SKK x = Kx (Kx) = Kx x

definitions • I x = x • K xy = x • S xyz = xz(yz) logic

Page 20: Combinators - Lightning Talk

I = SKK

I x = SKK x = Kx (Kx) = Kx x = xdefinitions • I x = x • K xy = x • S xyz = xz(yz) logic

Page 21: Combinators - Lightning Talk

Lightning!

Page 22: Combinators - Lightning Talk

Extensional Equality

csv.GetRecords<TTarget>() .Where(x => x.PricingDate != "") .Pipe(x => { x.FileId = fileId; }) …

C#

Page 23: Combinators - Lightning Talk

Thank you!

Mike Harris@MikeMKHhttp://comp-phil.blogspot.com/