Skip to content

Instantly share code, notes, and snippets.

View lorentey's full-sized avatar
⚙️

Karoy Lorentey lorentey

⚙️
View GitHub Profile
@lorentey
lorentey / noncopyable-stdlib-primitives.md
Last active May 22, 2024 00:18
Noncopyable Standard Library Primitives (draft proposal)

Noncopyable Standard Library Primitives

  • Proposal: SE-NNNN
  • Authors: Karoy Lorentey
  • Review Manager: TBD
  • Status: Awaiting review
  • Roadmap: [Improving Swift performance predictability: ARC improvements and ownership control][Roadmap]
  • Implementation:
    • The type/function generalizations are (provisionally) already present on main and release/6.0.
  • The proposed API additions are implemented by PRs #73807 (main) and #73810 (release/6.0).
@lorentey
lorentey / Package.swift
Created February 19, 2021 08:14
A Swift solver for the numbers game in Countdown
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "countdown-solver",
products: [
.executable(name: "countdown-solver", targets: ["countdown-solver"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"),
],
@lorentey
lorentey / Atomics.md
Last active October 29, 2024 18:56
[pitch] Low-Level Atomic Operations ⚛︎
@lorentey
lorentey / ivar-access-pitch.md
Last active November 8, 2019 04:22
[pitch] Exposing the memory locations of class instance variables
Hello
This sample file contains examples of all kinds of data that can be stored in a pile.
All text up to the first line that consists of a #pile version directive is ignored by the parser.
Feel free to write anything here.
This is how all text piles start: (The "1" is the version number of the file format.)
#pile:1
import Foundation
@objc class Person: NSObject {
var _firstName: String = "John"
var _lastName: String = "Smith"
dynamic var firstName: String { get { return _firstName } set { _firstName = newValue } }
dynamic var lastName: String { get { return _lastName } set { _lastName = newValue } }
dynamic var name: String { return "\(firstName) \(lastName)" }
protocol Sink {
associatedtype Value
func receive(_ value: Value)
}
// This assumes Generalized Existentials are a thing
// https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generalized-existentials
typealias AnySink<Value> = Any<Sink where .Value == Value>
protocol Source {
protocol Sink {
func receive()
}
protocol Source {
associatedtype Value
func subscribe(_ sink: Sink) -> Int
func unsubscribe(_ token: Int)
### Keybase proof
I hereby claim:
* I am lorentey on github.
* I am lorentey (https://keybase.io/lorentey) on keybase.
* I have a public key whose fingerprint is 086D 2046 8C31 E936 754F C0C7 E9EA 32A8 0FB2 7A3F
To claim this, I am signing this object:
@lorentey
lorentey / shadow.swift
Last active July 8, 2018 12:20
The most annoying thing about Swift 3's naming conventions is that some renamed members now shadow frequently used global functions:
extension Array where Element: Comparable {
func clamp(from lowerBound: Element, to upperBound: Element) -> Array {
return self.map { min(upperBound, max(lowerBound, $0)) }
}
}
let clamped = [0, 1, 2, 3, 4, 5, 6].clamp(from: 2, to: 4))