- 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"), | |
], |
- Author: Karoy Lorentey
- Version: 2020-04-13/1
- Document URL: https://gist.github.com/lorentey/cf8703b5974ebe8f85cfb92a6628880d
- Forum Thread: https://forums.swift.org/t/low-level-atomic-operations/34683
- Implementation:
- [swiftlang/swift#30553][implementation] (Atomic operations)
- [swiftlang/swift#26969][constantPR] (Constant-constrained ordering arguments)
We propose to enable Swift code to retrieve the memory location of any directly addressable stored property in a class instance as an UnsafeMutablePointer
value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Sink { | |
func receive() | |
} | |
protocol Source { | |
associatedtype Value | |
func subscribe(_ sink: Sink) -> Int | |
func unsubscribe(_ token: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
NewerOlder