Skip to content

Instantly share code, notes, and snippets.

@ffried
Created July 8, 2017 18:10
Show Gist options
  • Save ffried/ee6378885a39275b4e2fd6cd0461d9de to your computer and use it in GitHub Desktop.
Save ffried/ee6378885a39275b4e2fd6cd0461d9de to your computer and use it in GitHub Desktop.
Sample implementation of a lazy value wrapper
public struct Lazy<T> {
private let initialization: () -> T
public private(set) lazy var: T = self.initialization()
public init(initialization: () -> T) {
self.initialization = initialization
}
public init(other: Lazy<T>) {
self.init(initialization: other.initialization)
}
public mutating func reset() {
self = Lazy(other: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment