Skip to content

Instantly share code, notes, and snippets.

protocol Equatable2 {
//@memberwiseDerivable(mapper: equatable2Mapper, reducer: equatable2Reducer, reduceInitialResult: true)
static func == (_: Self, _: Self) -> Bool
}
// lhs and rhs come from the derived requirement, memberKeyPath is added to the argument list
// the return type must match the reducer's argument types
// Self is replaced by generic parameter T, U is the type of the member (which conforms to the given protocol)
func equatable2Mapper<T, U: Equatable2>(_ lhs: T, _ rhs: T, memberKeyPath: KeyPath<T, U>) -> Bool {
return lhs[keyPath: memberKeyPath] == rhs[keyPath: memberKeyPath]
@owenv
owenv / CustomLayout.swift
Created November 11, 2016 02:05
Composable Layout Objects in Swift
//
// CustomLayout.swift
// LayoutKit
//
// Created by Owen Voorhees on 10/6/16.
// Copyright © 2016 Owen Voorhees. All rights reserved.
//
//Lays out children using a custom set of constraints
public class CustomLayout: Layout {