Skip to content

Instantly share code, notes, and snippets.

View gsampaio's full-sized avatar

Guilherme Martinez Sampaio gsampaio

View GitHub Profile
@chriseidhof
chriseidhof / json.swift
Last active March 21, 2019 07:45
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {
@airspeedswift
airspeedswift / NonemptyCollection.swift
Created December 17, 2016 23:15
Non-empty collection in Swift
protocol NonemptyCollection: Collection {
var first: Iterator.Element { get }
}
enum NonemptyIndex<Base: Collection>: Comparable {
case head
case tail(Base.Index)
static func ==(lhs: NonemptyIndex, rhs: NonemptyIndex) -> Bool {
switch (lhs,rhs) {
@fellipecaetano
fellipecaetano / Redux.swift
Last active January 15, 2018 20:08
Extending Redux with an effect system
/* Credits to @gsampaio for coming up with the Effect<S, A> type.
* Even though this flavor of reducer also describes side-effects,
* testing is still trivial since it's sufficient to check if the
* side-effects are of the right type. The actual execution of the
* effect can be tested separately using integration tests. */
import RxSwift
class Effect<S: Equatable, A: Action> {
open func execute(state: () -> S) -> Observable<A> {
@marmoy
marmoy / DictionaryEncoder.swift
Created April 2, 2018 09:48
A DictionaryEncoder to be used with the Encodable protocol, based on the default PropertyListEncoder from the Swift project
//===----------------------------------------------------------------------===//
//
// This source file is a modification of the PropertyListEncoder from the Swift project.
// The modification consists of skipping the final serialization into binary format (in the encode function) and instead returning the dictionary representation of the object to be encoded.
//
//===----------------------------------------------------------------------===//
import Foundation
//===----------------------------------------------------------------------===//