Skip to content

Instantly share code, notes, and snippets.

import Foundation
protocol StageProtocol {
func perform() throws -> Self?
var queue: dispatch_queue_t { get }
func run(completion: (() throws -> Self) -> ())
}
enum Fruit {
case apple, pear, orange, plum
}
extension Fruit {
var cents: Int {
return switch self [
.apple: 70,
.pear: 85,
.orange: 40,
@RoyalIcing
RoyalIcing / Mutation.swift
Last active April 22, 2016 08:09
Mutation methods as a type, allowing easy copies to be made
struct Person {
var firstName, lastName: String
mutating func makeScottishClan() {
lastName = "mc\(lastName)"
}
}
// Person.Mutation gets automatically created (like an enum)
// .firstName(String)
//: Playground - noun: a place where people can play
import Foundation
struct ExampleStruct : Codable {
var title: String
var something: Int
public func encode(to encoder: Encoder) throws {
//: Types for currency conversion
// https://www.natashatherobot.com/swift-money-phantom-types/
import Foundation
struct Money {
enum Currency {
case GBP, EUR, USD
}
@RoyalIcing
RoyalIcing / responder-chain.swift
Last active February 13, 2018 16:05
Responder chain in Swift using enums
//: Responder chain in Swift using enums
protocol CommandProtocol {}
protocol Responder: class {
var nextResponder: Responder? { get }
func performerForCommand
<Command : CommandProtocol>
(command: Command) -> (() -> ())?
@RoyalIcing
RoyalIcing / 1.ts
Created June 29, 2018 02:02
React state management ideas
interface State {
counter: number
}
const counterModel = {
initial(): State {
return {
counter: 0
};
},
@RoyalIcing
RoyalIcing / keybase.md
Created November 7, 2018 13:25
keybase.md

Keybase proof

I hereby claim:

  • I am burntcaramel on github.
  • I am burntcaramel (https://keybase.io/burntcaramel) on keybase.
  • I have a public key ASArnj22CZ7v-9tbcz-52hippT2ZfvGy4dQ3ZoSelHe3lwo

To claim this, I am signing this object:

@RoyalIcing
RoyalIcing / SequenceType+compact.swift
Last active February 1, 2019 16:54
Swift compact() for SequenceType
//: Playground - noun: a place where people can play
import Foundation
protocol OptionalParasite {
typealias WrappedParasite
func toArray() -> [WrappedParasite]
}
@RoyalIcing
RoyalIcing / 1-example.swift
Created May 27, 2016 13:36
Swift Dynamic Properties
public struct Person {
public var firstName: String
public var middleName: String?
public var lastName: String
public var ageInYears: Int
public var fullName: String {
return [firstName, middleName, lastName].flatMap{ $0 }.joinWithSeparator(" ")
}
}