Skip to content

Instantly share code, notes, and snippets.

// Monoid
precedencegroup MonoidPrecedence {
associativity: left
}
infix operator <> : MonoidPrecedence
protocol Monoid {
static var empty: Self { get }
struct AnyEncodable: Encodable {
let base: Encodable
init(_ value: Encodable) {
base = value
}
func encode(to encoder: Encoder) throws {
try base.encode(to: encoder)
}
import Foundation
extension Notification {
struct TypedName<Value> {
let rawValue: String
init(_ rawValue: String) {
self.rawValue = rawValue
}
extension String {
init<T>(dumping x: T) {
self.init()
dump(x, to: &self)
}
}
func assertDumpsEqual<T>(_ lhs: @autoclosure () -> T, _ rhs: @autoclosure () -> T, file: StaticString = #file, line: UInt = #line) {
assert(String(dumping: lhs()) == String(dumping: rhs()), "Expected dumps to be equal.", file: file, line: line)
}