├── .swift-version ├── .swiftpm └── xcode │ └── package.xcworkspace │ └── contents.xcworkspacedata ├── Sources └── SwiftLazy │ ├── PrefixOperator.swift │ ├── BaseProvider.swift │ ├── BaseLazy.swift │ ├── ProviderArgs.swift │ ├── Provider.swift │ └── Lazy.swift ├── Package.swift ├── LICENSE ├── .gitignore └── README.md /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sources/SwiftLazy/PrefixOperator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PrefixOperator.swift 3 | // SwiftLazy 4 | // 5 | // Created by Alexander Ivlev on 19.11.2025. 6 | // Copyright © 2025 Alexander Ivlev. All rights reserved. 7 | // 8 | 9 | prefix operator * 10 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.9 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "SwiftLazy", 6 | platforms: [.iOS(.v13), .watchOS(.v8), .macOS(.v10_15), .tvOS(.v13)], 7 | products: [.library(name: "SwiftLazy", targets: ["SwiftLazy"])], 8 | targets: [.target(name: "SwiftLazy", dependencies: [])] 9 | ) 10 | -------------------------------------------------------------------------------- /Sources/SwiftLazy/BaseProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaseProvider.swift 3 | // SwiftLazy 4 | // 5 | // Created by Ивлев Александр Евгеньевич on 27/09/2018. 6 | // Copyright © 2018 Alexander Ivlev. All rights reserved. 7 | // 8 | 9 | public class BaseProvider: @unchecked Sendable { 10 | 11 | /// The value for `self`. 12 | /// 13 | /// Made the value and return. 14 | internal func getValue(_ initializer: () -> Value) -> Value { 15 | return initializer() 16 | } 17 | 18 | } 19 | 20 | extension BaseProvider: CustomStringConvertible, CustomDebugStringConvertible { 21 | 22 | /// A textual representation of this instance. 23 | public var description: String { 24 | return "Provider(\(Value.self))" 25 | } 26 | 27 | /// A textual representation of this instance, suitable for debugging. 28 | public var debugDescription: String { 29 | return "Provider(\(Value.self))" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ivlev Alexander 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /Sources/SwiftLazy/BaseLazy.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLazy.swift 3 | // SwiftLazy 4 | // 5 | // Created by Ивлев Александр Евгеньевич on 27/09/2018. 6 | // Copyright © 2018 Alexander Ivlev. All rights reserved. 7 | // 8 | 9 | import Dispatch 10 | 11 | public class BaseThreadSaveLazy: @unchecked Sendable { 12 | 13 | /// `true` if `self` was previously made. 14 | public var wasMade: Bool { 15 | lock.readLock() 16 | defer { lock.unlock() } 17 | return cache != nil 18 | } 19 | 20 | /// clears the stored value. 21 | public func clear() { 22 | lock.writeLock() 23 | defer { lock.unlock() } 24 | cache = nil 25 | } 26 | 27 | internal func getValue(_ initializer: () -> Value) -> Value { 28 | lock.readLock() 29 | if let cache { 30 | lock.unlock() 31 | return cache 32 | } 33 | lock.unlock() 34 | 35 | lock.writeLock() 36 | defer { lock.unlock() } 37 | 38 | if let cache { 39 | return cache 40 | } 41 | 42 | let result = initializer() 43 | cache = result 44 | 45 | return result 46 | } 47 | 48 | private let lock = RWLock() 49 | 50 | private var cache: Value? 51 | } 52 | 53 | extension BaseThreadSaveLazy: CustomStringConvertible, CustomDebugStringConvertible { 54 | 55 | /// A textual representation of this instance. 56 | public var description: String { 57 | let cache = self.cache 58 | let value = cache.flatMap(String.init(describing:)) ?? "nil" 59 | return "Lazy(\(value))" 60 | } 61 | 62 | /// A textual representation of this instance, suitable for debugging. 63 | public var debugDescription: String { 64 | let cache = self.cache 65 | let value = cache.flatMap(String.init(describing:)) ?? "nil" 66 | return "Lazy(\(value): \(Value.self))" 67 | } 68 | } 69 | 70 | private final class RWLock { 71 | private var lock = pthread_rwlock_t() 72 | 73 | init() { 74 | pthread_rwlock_init(&lock, nil) 75 | } 76 | 77 | deinit { 78 | pthread_rwlock_destroy(&lock) 79 | } 80 | 81 | func writeLock() { 82 | pthread_rwlock_wrlock(&lock) 83 | } 84 | 85 | func readLock() { 86 | pthread_rwlock_rdlock(&lock) 87 | } 88 | 89 | func unlock() { 90 | pthread_rwlock_unlock(&lock) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Sources/SwiftLazy/ProviderArgs.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProviderArgs.swift 3 | // SwiftLazy 4 | // 5 | // Created by Ивлев Александр Евгеньевич on 27/09/2018. 6 | // Copyright © 2018 Alexander Ivlev. All rights reserved. 7 | // 8 | 9 | public final class Provider1: BaseProvider, @unchecked Sendable { 10 | public func value(_ arg1: Arg1) -> Value { 11 | return self.getValue { return self.initializer(arg1) } 12 | } 13 | 14 | private var initializer: (Arg1) -> Value 15 | 16 | public init(_ initializer: @escaping (Arg1) -> Value) { 17 | self.initializer = initializer 18 | } 19 | } 20 | 21 | public final class Provider2: BaseProvider, @unchecked Sendable { 22 | public func value(_ arg1: Arg1, _ arg2: Arg2) -> Value { 23 | return self.getValue { return self.initializer(arg1, arg2) } 24 | } 25 | 26 | private var initializer: (Arg1, Arg2) -> Value 27 | 28 | public init(_ initializer: @escaping (Arg1, Arg2) -> Value) { 29 | self.initializer = initializer 30 | } 31 | } 32 | 33 | public final class Provider3: BaseProvider, @unchecked Sendable { 34 | public func value(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Value { 35 | return self.getValue { return self.initializer(arg1, arg2, arg3) } 36 | } 37 | 38 | private var initializer: (Arg1, Arg2, Arg3) -> Value 39 | 40 | public init(_ initializer: @escaping (Arg1, Arg2, Arg3) -> Value) { 41 | self.initializer = initializer 42 | } 43 | } 44 | 45 | public final class Provider4: BaseProvider, @unchecked Sendable { 46 | public func value(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Value { 47 | return self.getValue { return self.initializer(arg1, arg2, arg3, arg4) } 48 | } 49 | 50 | private var initializer: (Arg1, Arg2, Arg3, Arg4) -> Value 51 | 52 | public init(_ initializer: @escaping (Arg1, Arg2, Arg3, Arg4) -> Value) { 53 | self.initializer = initializer 54 | } 55 | } 56 | 57 | public final class Provider5: BaseProvider, @unchecked Sendable { 58 | public func value(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Value { 59 | return self.getValue { return self.initializer(arg1, arg2, arg3, arg4, arg5) } 60 | } 61 | 62 | private var initializer: (Arg1, Arg2, Arg3, Arg4, Arg5) -> Value 63 | 64 | public init(_ initializer: @escaping (Arg1, Arg2, Arg3, Arg4, Arg5) -> Value) { 65 | self.initializer = initializer 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CocoaPods Version](https://img.shields.io/cocoapods/v/SwiftLazy.svg?style=flat)](http://cocoapods.org/pods/SwiftLazy) 2 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 3 | [![License](https://img.shields.io/github/license/ivlevAstef/SwiftLazy.svg?maxAge=2592000)](http://cocoapods.org/pods/SwiftLazy) 4 | [![Swift Version](https://img.shields.io/badge/Swift-3.0--5.8-F16D39.svg?style=flat)](https://developer.apple.com/swift) 5 | [![Platform](https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-lightgrey.svg)](http://cocoapods.org/pods/SwiftLazy) 6 | 7 | # SwiftLazy 8 | Swift allows for lazy variables out-of-the-box, however they're fairly restricted. 9 | 10 | ## Features 11 | * Lazy and Provider operations 12 | * Short syntax 13 | * Thread safe 14 | 15 | ## Usage 16 | 17 | ### Lazy 18 | 19 | ```Swift 20 | let lazyInt = Lazy(1) 21 | print(lazyInt.wasMade) // false 22 | print(lazyInt.value) // 1 23 | print(lazyInt.wasMade) // true 24 | ``` 25 | 26 | Support arithmetic operations: 27 | ```Swift 28 | let lazyInt = Lazy{ 1 + 2 * 5 } * 4 + 10 29 | print(lazyInt.wasMade) // false 30 | print(lazyInt.value) // 54 31 | print(lazyInt.wasMade) // true 32 | ``` 33 | 34 | Short syntax: 35 | ```Swift 36 | let lazyInt = Lazy(1) 37 | print(*lazyInt) // 1 38 | ``` 39 | 40 | ### Provider 41 | 42 | ```Swift 43 | let providerInt = Provider(1) 44 | print(lazyInt.value) // 1 45 | ``` 46 | 47 | Support arithmetic operations: 48 | ```Swift 49 | let providerInt = Provider{ 1 + 2 * 5 } * 4 + 10 50 | print(providerInt.value) // 54 51 | ``` 52 | 53 | Short syntax: 54 | ```Swift 55 | let providerInt = Provider(1) 56 | print(*providerInt) // 1 57 | ``` 58 | 59 | ### Difference Lazy vs Provider 60 | 61 | ```Swift 62 | var counter: Int = 0 63 | let lazyInt = Lazy { 64 | counter += 1 65 | return counter 66 | } 67 | 68 | print(lazyInt.value) // 1 69 | print(lazyInt.value) // 1 70 | print(lazyInt.value) // 1 71 | 72 | lazyInt.clear() // no provider 73 | print(lazyInt.value) // 2 74 | print(lazyInt.value) // 2 75 | print(lazyInt.value) // 2 76 | ``` 77 | 78 | ```Swift 79 | var counter: Int = 0 80 | let providerInt = Provider { 81 | counter += 1 82 | return counter 83 | } 84 | 85 | print(providerInt.value) // 1 86 | print(providerInt.value) // 2 87 | print(providerInt.value) // 3 88 | ``` 89 | 90 | ### Version 1.1.0 91 | 92 | Add Provider with arguments: 93 | ```Swift 94 | let provider = Provider2 { "\($0) + \($1) = \($0 + $1)" } 95 | 96 | print(provider.value(10, 20.0)) // "10 + 20.0 = 30.0" 97 | ``` 98 | Support 1, 2, 3, 4, 5 arguments count. 99 | 100 | ## Install 101 | ###### Via CocoaPods. 102 | 103 | To install SwiftLazy with CocoaPods, add the following lines to your Podfile: `pod 'SwiftLazy'` 104 | 105 | ###### Via Carthage. 106 | github "ivlevAstef/SwiftLazy" 107 | 108 | ### The library is integrated with DITranquillity 109 | 110 | ## Requirements 111 | iOS 11.0+,macOS 10.13+,tvOS 11.0+, watchOS 4.0+, Linux; ARC 112 | 113 | ## Feedback 114 | 115 | ### I've found a bug, or have a feature request 116 | Please raise a [GitHub issue](https://github.com/ivlevAstef/SwiftLazy/issues). 117 | 118 | ### Question? 119 | You can feel free to ask the question at e-mail: ivlev.stef@gmail.com. 120 | -------------------------------------------------------------------------------- /Sources/SwiftLazy/Provider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Provider.swift 3 | // SwiftLazy 4 | // 5 | // Created by Alexander Ivlev on 08.04.2018. 6 | // Copyright © 2018 Alexander Ivlev. All rights reserved. 7 | // 8 | 9 | public final class Provider: BaseProvider, @unchecked Sendable { 10 | 11 | /// The value for `self`. 12 | /// 13 | /// Made the value and return. 14 | public var value: Value { 15 | return self.getValue(self.initializer) 16 | } 17 | 18 | private var initializer: () -> Value 19 | 20 | /// Create a provider value. 21 | public init(_ initializer: @autoclosure @escaping () -> Value) { 22 | self.initializer = initializer 23 | } 24 | 25 | /// Create a provider value. 26 | public init(_ initializer: @escaping () -> Value) { 27 | self.initializer = initializer 28 | } 29 | } 30 | 31 | 32 | extension Provider { 33 | 34 | /// Maps `transform` over `value` and returns a provider result. 35 | public func map(_ transform: @escaping (Value) -> T) -> Provider { 36 | return Provider { () -> T in 37 | return transform(self.value) 38 | } 39 | } 40 | } 41 | 42 | /// Fast syntax for getting the value for Lazy. 43 | public prefix func *(_ wrapper: Provider) -> T { 44 | return wrapper.value 45 | } 46 | 47 | /// MARK: Compare 48 | 49 | public func == >(lhs: Provider, rhs: Provider) -> Provider { 50 | return Provider(lhs.value == rhs.value) 51 | } 52 | 53 | public func == (lhs: Provider, rhs: T) -> Provider { 54 | return Provider(lhs.value == rhs) 55 | } 56 | 57 | public func == (lhs: T, rhs: Provider) -> Provider { 58 | return Provider(lhs == rhs.value) 59 | } 60 | 61 | /// MARK: Operations 62 | 63 | public func - (lhs: Provider, rhs: Provider) -> Provider { 64 | return Provider(lhs.value - rhs.value) 65 | } 66 | 67 | public func - (lhs: Provider, rhs: T) -> Provider { 68 | return Provider(lhs.value - rhs) 69 | } 70 | 71 | public func - (lhs: T, rhs: Provider) -> Provider { 72 | return Provider(lhs - rhs.value) 73 | } 74 | 75 | public func + (lhs: Provider, rhs: Provider) -> Provider { 76 | return Provider(lhs.value + rhs.value) 77 | } 78 | 79 | public func + (lhs: Provider, rhs: T) -> Provider { 80 | return Provider(lhs.value + rhs) 81 | } 82 | 83 | public func + (lhs: T, rhs: Provider) -> Provider { 84 | return Provider(lhs + rhs.value) 85 | } 86 | 87 | public func * (lhs: Provider, rhs: Provider) -> Provider { 88 | return Provider(lhs.value * rhs.value) 89 | } 90 | 91 | public func * (lhs: Provider, rhs: T) -> Provider { 92 | return Provider(lhs.value * rhs) 93 | } 94 | 95 | public func * (lhs: T, rhs: Provider) -> Provider { 96 | return Provider(lhs * rhs.value) 97 | } 98 | 99 | public func / (lhs: Provider, rhs: Provider) -> Provider { 100 | return Provider(lhs.value / rhs.value) 101 | } 102 | 103 | public func / (lhs: Provider, rhs: T) -> Provider { 104 | return Provider(lhs.value / rhs) 105 | } 106 | 107 | public func / (lhs: T, rhs: Provider) -> Provider { 108 | return Provider(lhs / rhs.value) 109 | } 110 | 111 | public func % (lhs: Provider, rhs: Provider) -> Provider { 112 | return Provider(lhs.value % rhs.value) 113 | } 114 | 115 | public func % (lhs: Provider, rhs: T) -> Provider { 116 | return Provider(lhs.value % rhs) 117 | } 118 | 119 | public func % (lhs: T, rhs: Provider) -> Provider { 120 | return Provider(lhs % rhs.value) 121 | } 122 | 123 | public func & (lhs: Provider, rhs: Provider) -> Provider { 124 | return Provider(lhs.value & rhs.value) 125 | } 126 | 127 | public func & (lhs: Provider, rhs: T) -> Provider { 128 | return Provider(lhs.value & rhs) 129 | } 130 | 131 | public func & (lhs: T, rhs: Provider) -> Provider { 132 | return Provider(lhs & rhs.value) 133 | } 134 | 135 | public func | (lhs: Provider, rhs: Provider) -> Provider { 136 | return Provider(lhs.value | rhs.value) 137 | } 138 | 139 | public func | (lhs: Provider, rhs: T) -> Provider { 140 | return Provider(lhs.value | rhs) 141 | } 142 | 143 | public func | (lhs: T, rhs: Provider) -> Provider { 144 | return Provider(lhs | rhs.value) 145 | } 146 | 147 | public func ^ (lhs: Provider, rhs: Provider) -> Provider { 148 | return Provider(lhs.value ^ rhs.value) 149 | } 150 | 151 | public func ^ (lhs: Provider, rhs: T) -> Provider { 152 | return Provider(lhs.value ^ rhs) 153 | } 154 | 155 | public func ^ (lhs: T, rhs: Provider) -> Provider { 156 | return Provider(lhs ^ rhs.value) 157 | } 158 | 159 | public prefix func ~ (x: Provider) -> Provider { 160 | return Provider(~x.value) 161 | } 162 | 163 | -------------------------------------------------------------------------------- /Sources/SwiftLazy/Lazy.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lazy.swift 3 | // SwiftLazy 4 | // 5 | // Created by Alexander Ivlev on 08.04.2018. 6 | // Copyright © 2018 Alexander Ivlev. All rights reserved. 7 | // 8 | 9 | @dynamicMemberLookup 10 | public final class Lazy: BaseThreadSaveLazy, @unchecked Sendable { 11 | 12 | /// The value for `self`. 13 | /// 14 | /// Getting the value or made and return. 15 | public var value: Value { 16 | return getValue(initializer) 17 | } 18 | 19 | private let initializer: () -> Value 20 | 21 | /// Create a lazy value. 22 | public init(_ initializer: @autoclosure @escaping () -> Value) { 23 | self.initializer = initializer 24 | } 25 | 26 | /// Create a lazy value. 27 | public init(_ initializer: @escaping () -> Value) { 28 | self.initializer = initializer 29 | } 30 | 31 | /// `true` if `self` was previously made. 32 | public override var wasMade: Bool { return super.wasMade } 33 | 34 | /// clears the stored value. 35 | public override func clear() { super.clear() } 36 | 37 | /// For use lazy value, without write `.value` 38 | public subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> R { 39 | get { value[keyPath: keyPath] } 40 | set { value[keyPath: keyPath] = newValue } 41 | } 42 | } 43 | 44 | 45 | extension Lazy { 46 | 47 | /// Maps `transform` over `value` and returns a lazy result. 48 | public func map(_ transform: @escaping (Value) -> T) -> Lazy { 49 | return Lazy { () -> T in 50 | return transform(self.value) 51 | } 52 | } 53 | } 54 | 55 | /// Fast syntax for getting the value for Lazy. 56 | public prefix func *(_ wrapper: Lazy) -> T { 57 | return wrapper.value 58 | } 59 | 60 | /// MARK: Compare 61 | 62 | public func == >(lhs: Lazy, rhs: Lazy) -> Lazy { 63 | return Lazy(lhs.value == rhs.value) 64 | } 65 | 66 | public func == (lhs: Lazy, rhs: T) -> Lazy { 67 | return Lazy(lhs.value == rhs) 68 | } 69 | 70 | public func == (lhs: T, rhs: Lazy) -> Lazy { 71 | return Lazy(lhs == rhs.value) 72 | } 73 | 74 | /// MARK: Operations 75 | 76 | public func - (lhs: Lazy, rhs: Lazy) -> Lazy { 77 | return Lazy(lhs.value - rhs.value) 78 | } 79 | 80 | public func - (lhs: Lazy, rhs: T) -> Lazy { 81 | return Lazy(lhs.value - rhs) 82 | } 83 | 84 | public func - (lhs: T, rhs: Lazy) -> Lazy { 85 | return Lazy(lhs - rhs.value) 86 | } 87 | 88 | public func + (lhs: Lazy, rhs: Lazy) -> Lazy { 89 | return Lazy(lhs.value + rhs.value) 90 | } 91 | 92 | public func + (lhs: Lazy, rhs: T) -> Lazy { 93 | return Lazy(lhs.value + rhs) 94 | } 95 | 96 | public func + (lhs: T, rhs: Lazy) -> Lazy { 97 | return Lazy(lhs + rhs.value) 98 | } 99 | 100 | public func * (lhs: Lazy, rhs: Lazy) -> Lazy { 101 | return Lazy(lhs.value * rhs.value) 102 | } 103 | 104 | public func * (lhs: Lazy, rhs: T) -> Lazy { 105 | return Lazy(lhs.value * rhs) 106 | } 107 | 108 | public func * (lhs: T, rhs: Lazy) -> Lazy { 109 | return Lazy(lhs * rhs.value) 110 | } 111 | 112 | public func / (lhs: Lazy, rhs: Lazy) -> Lazy { 113 | return Lazy(lhs.value / rhs.value) 114 | } 115 | 116 | public func / (lhs: Lazy, rhs: T) -> Lazy { 117 | return Lazy(lhs.value / rhs) 118 | } 119 | 120 | public func / (lhs: T, rhs: Lazy) -> Lazy { 121 | return Lazy(lhs / rhs.value) 122 | } 123 | 124 | public func % (lhs: Lazy, rhs: Lazy) -> Lazy { 125 | return Lazy(lhs.value % rhs.value) 126 | } 127 | 128 | public func % (lhs: Lazy, rhs: T) -> Lazy { 129 | return Lazy(lhs.value % rhs) 130 | } 131 | 132 | public func % (lhs: T, rhs: Lazy) -> Lazy { 133 | return Lazy(lhs % rhs.value) 134 | } 135 | 136 | public func & (lhs: Lazy, rhs: Lazy) -> Lazy { 137 | return Lazy(lhs.value & rhs.value) 138 | } 139 | 140 | public func & (lhs: Lazy, rhs: T) -> Lazy { 141 | return Lazy(lhs.value & rhs) 142 | } 143 | 144 | public func & (lhs: T, rhs: Lazy) -> Lazy { 145 | return Lazy(lhs & rhs.value) 146 | } 147 | 148 | public func | (lhs: Lazy, rhs: Lazy) -> Lazy { 149 | return Lazy(lhs.value | rhs.value) 150 | } 151 | 152 | public func | (lhs: Lazy, rhs: T) -> Lazy { 153 | return Lazy(lhs.value | rhs) 154 | } 155 | 156 | public func | (lhs: T, rhs: Lazy) -> Lazy { 157 | return Lazy(lhs | rhs.value) 158 | } 159 | 160 | public func ^ (lhs: Lazy, rhs: Lazy) -> Lazy { 161 | return Lazy(lhs.value ^ rhs.value) 162 | } 163 | 164 | public func ^ (lhs: Lazy, rhs: T) -> Lazy { 165 | return Lazy(lhs.value ^ rhs) 166 | } 167 | 168 | public func ^ (lhs: T, rhs: Lazy) -> Lazy { 169 | return Lazy(lhs ^ rhs.value) 170 | } 171 | 172 | public prefix func ~ (x: Lazy) -> Lazy { 173 | return Lazy(~x.value) 174 | } 175 | --------------------------------------------------------------------------------