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
// | |
// 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 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
/// 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
// 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) | |
} | |
} |
NewerOlder