Skip to content

Instantly share code, notes, and snippets.

View plumhead's full-sized avatar

Andy Calderbank plumhead

View GitHub Profile
@plumhead
plumhead / gist:bf359b6fc3833ebd3cd2
Created June 8, 2014 21:09
Partition and Choose
operator infix |> {associativity left precedence 140}
func |> <T,U> (left: @auto_closure () -> T,right: T -> U) -> U {
return right(left())
}
func partition<T>(f : T -> Bool)(a : Array<T>) -> (left: Array<T>, right: Array<T>) {
var (leftpartition,rightpartition) = (Array<T>(),Array<T>())
for (index, value) in enumerate(a) {
@plumhead
plumhead / gist:c4597bdda147073cf791
Created June 6, 2014 22:01
Hiding GCD behing Async
//
// Async.swift
// TestSwiftUI
//
// Created by Plumhead on 06/06/2014.
//
// There are many holes in this which will be ironed out over time - put up as a starting point for ideas
//
import Foundation
operator infix |> {associativity left precedence 140}
func |> <T,U> (left: @auto_closure () -> T,right: T -> U) -> U {
return right(left())
}
func add(n1 : Int)(n2: Int) -> Int {return n1 + n2}
let addone = add(1)
let addtwo = add(2)
let a1 = addone(n2:10) |> addone |> addtwo
@plumhead
plumhead / gist:9ac80e348c2c4533b761
Last active August 29, 2015 14:02
FSharp Fib Pipeline
/// Fibonacci Number formula
let rec fib n =
match n with
| 0 | 1 -> n
| _ -> fib (n - 1) + fib (n - 2)
// Print even fibs
[1 .. 10]
|> List.map fib
|> List.filter (fun n -> (n % 2) = 0)
@plumhead
plumhead / gist:a4955117bbda5f6bab6f
Last active August 29, 2015 14:02
Swift Fib Pipe
// a copy of the f# fib implementation
func fib(n : Int) -> Int {
if n == 0 || n == 1 {
return n
}
else {
return fib(n - 1) + fib(n - 2)
}
}