Skip to content

Instantly share code, notes, and snippets.

@pgorzelany
pgorzelany / ProtocolExtensions.swift
Last active January 15, 2016 19:06
Shows the edge cases of protocol extension and implementation in Swift
// Protocol defines a mandatory function
protocol FooType {
func introduce() -> Void
}
// Default implementation of the protocol requirement
extension FooType {
func introduce() {
print("This is the FooType")
}
@pgorzelany
pgorzelany / SPSimulation.swift
Last active September 23, 2015 10:10
Contains a collection of methods and data types needed to perform a random walk simulation of a stock price
//
// Created by Piotr Gorzelany on 23/09/15.
// Copyright © 2015 Piotr Gorzelany. All rights reserved.
//
/** Contains a collection of methods and data types needed to perform a random walk simulation of a stock price.
The random walk is based on an asumption of a normal distribution of the stock daily rates of return. */
public struct SPSimulation {
/** Contains stock information needed to perform a simulation */
@pgorzelany
pgorzelany / pipes.swift
Last active September 23, 2015 07:35
Basic pipes implementation in Swift
/* Used for piping the results of consecutive functions
*/
infix operator |> { associativity left precedence 140 }
func |> <I, O>(input: I, transform: (I) -> O) -> O {
return transform(input)
}
let root = 4 + 3 * 4 |> {Double($0)} |> sqrt
print(root) // 4