Skip to content

Instantly share code, notes, and snippets.

//Exercises from https://www.pointfree.co/episodes/ep9-algebraic-data-types-exponents
import UIKit
enum Either<A,B> {
case left(A)
case right(B)
}
struct Pair<A,B> {
@pedrocid
pedrocid / Subscripts.swift
Created March 19, 2016 11:18
Custom subscripts in Swift
import UIKit
class Thing {
var name: String
var quantity: Int
init(name: String, quantity: Int){
self.name = name
@pedrocid
pedrocid / CovarianceContravariance.swift
Created March 2, 2016 14:02
Examples os covariance and contravariance in Swift
//MARK: From https://mikeash.com/pyblog/friday-qa-2015-11-20-covariance-and-contravariance.html
import UIKit
//MARK: TYPE VARIANCE LESSON
//First we explore supertypes and subtypes
class Thing {}
class Vehicle: Thing {}
@pedrocid
pedrocid / AbstractFactory.swift
Created February 21, 2016 10:21
Abstract Factory Pattern Example
//MARK: Abstract factory pattern
protocol AbstractProductA{
func display() -> String
}
protocol AbstractProductB{
func display() -> String
@pedrocid
pedrocid / ConstructionBuilderPattern.swift
Created February 9, 2016 19:27
Example of Construction Builder in Swift
struct ObjectToConstruct {
let propertyOne: String?
let propertyTwo: Array<String>?
let propertyThree: Bool?
}
class ConstructBuilder {