Skip to content

Instantly share code, notes, and snippets.

View antonvmironov's full-sized avatar

Anton Myronov antonvmironov

  • Amsterdam, Netherlands
View GitHub Profile
@antonvmironov
antonvmironov / universal imports.swift
Created October 21, 2025 12:39
universal imports for cross platform development
// from https://github.com/apple/swift-log/blob/main/Sources/Logging/MetadataProvider.swift#L15
#if canImport(Darwin) // macOS, iOS, tvOS, visionOS, ...
import Darwin
#elseif os(Windows)
import CRT
#elseif canImport(Glibc) // vanilla linux
import Glibc
#elseif canImport(Android)
import Android
#elseif canImport(Musl) // ...The Static Linux SDK does not use Glibc; instead, it is built on top of an alternative C library for Linux called Musl...
@antonvmironov
antonvmironov / associated-type-requirement-is-not-satisfiable.swift
Created March 18, 2017 20:49
Unable to satisfy associated type requirement in derived protocol
protocol BaseProtocol {
associatedtype Base
func export(base: Base) -> String
}
protocol ExtendedProtocol: BaseProtocol {
associatedtype Left
associatedtype Right
typealias Base = (left: Left, right: Right) // associatedtype requirement must be satisfied here
@antonvmironov
antonvmironov / my_super_transformations.swift
Created March 18, 2017 20:29
This is a simple way of making transformations that return type you want without higher-kinded types
protocol SequenceYouCanInsertInto: Sequence {
init()
mutating func mySuperInsert(_ element: Iterator.Element)
}
extension Sequence {
func mySuperFilter<T: SequenceYouCanInsertInto>(_ predicate: (Iterator.Element) throws -> Bool) rethrows -> T where Iterator.Element == T.Iterator.Element {
var result = T()
for value in self {