Skip to content

Instantly share code, notes, and snippets.

View jenox's full-sized avatar
:octocat:

Christian Schnorr jenox

:octocat:
View GitHub Profile
@jenox
jenox / CartesianProduct.swift
Last active June 20, 2022 03:58
CartesianProduct<_,_>
import Swift
public struct CartesianProduct<Base1, Base2> where Base1: Collection, Base2: Collection {
@usableFromInline internal let base1: Base1
@usableFromInline internal let base2: Base2
@inlinable
internal init(base1: Base1, base2: Base2) {
self.base1 = base1
self.base2 = base2
@jenox
jenox / ConditionalWrapper.swift
Created March 15, 2020 20:07
Conditional conformances and dynamic dispatch
import Swift
struct ConditionalWrapper<Base> where Base: Sequence {
fileprivate let base: Base
}
extension Sequence {
func conditionalWrapper() -> ConditionalWrapper<Self> {
return ConditionalWrapper(base: self)
}
@jenox
jenox / MutatingSlices.swift
Last active June 20, 2022 03:51
Performing mutating operations on slices cause copies that are later written back to the source collection. Thus `array[range].sort()` is less efficient than a hypothetical `array.sort(in: range)`.
class Box<T> {
init(value: T) {
self.value = value
}
var value: T
}
struct MyArray<T> {
private var storage: Box<[T]> = Box(value: [])
}
import Swift
extension UIApplication {
@discardableResult
public static func launch(with delegateClass: UIApplicationDelegate.Type) -> Int32 {
let type = UnsafeMutablePointer<Int8>.self
let count = Int(CommandLine.argc)
let principalClassName = NSStringFromClass(self)
let delegateClassName = NSStringFromClass(delegateClass)