Created
July 8, 2017 18:10
-
-
Save ffried/ee6378885a39275b4e2fd6cd0461d9de to your computer and use it in GitHub Desktop.
Sample implementation of a lazy value wrapper
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
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