This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import UIKit | |
import Foundation | |
import Swift | |
class MySingleton { | |
var amount : Float! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operator infix |> {associativity left precedence 140} | |
func |> <T,U> (left: @auto_closure () -> T,right: T -> U) -> U { | |
return right(left()) | |
} | |
func fold<S,T>(f : (S,T) -> S,acc: S)(s : Array<T>) -> S { | |
if s.isEmpty { | |
return acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getOrElse<S>(f : @auto_closure () -> S)(a : S?) -> S { | |
if let r = a { | |
return r | |
} | |
else { | |
return f() | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Times2Generator : Generator { | |
typealias Element = (original: Int,timestwo: Int)? | |
func next() -> Element? { | |
if source.count > 0 { | |
let result = self.source[0] | |
source = Array(source[1..source.count]) | |
return (result,result * 2) | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// Investigations on Protocols and function delegates | |
/* | |
The accepted way of doing things | |
*/ | |
protocol ProtoDelegate { |
OlderNewer