# SwiftLazy1.1.9

Maintained by Ivlev Alexander.

# SwiftLazy1.1.9

• By
• Alexander.Ivlev

# SwiftLazy

Swift allows for lazy variables out-of-the-box, however they're fairly restricted.

## Features

• Lazy and Provider operations
• Short syntax

## Usage

### Lazy

```let lazyInt = Lazy(1)
print(lazyInt.value) // 1

Support arithmetic operations:

```let lazyInt = Lazy<Int>{ 1 + 2 * 5 } * 4 + 10
print(lazyInt.value) // 54

Short syntax:

```let lazyInt = Lazy(1)
print(*lazyInt) // 1```

### Provider

```let providerInt = Provider(1)
print(lazyInt.value) // 1```

Support arithmetic operations:

```let providerInt = Provider<Int>{ 1 + 2 * 5 } * 4 + 10
print(providerInt.value) // 54```

Short syntax:

```let providerInt = Provider(1)
print(*providerInt) // 1```

### Difference Lazy vs Provider

```var counter: Int = 0
let lazyInt = Lazy<Int> {
counter += 1
return counter
}

print(lazyInt.value) // 1
print(lazyInt.value) // 1
print(lazyInt.value) // 1

lazyInt.clear() // no provider
print(lazyInt.value) // 2
print(lazyInt.value) // 2
print(lazyInt.value) // 2```
```var counter: Int = 0
let providerInt = Provider<Int> {
counter += 1
return counter
}

print(providerInt.value) // 1
print(providerInt.value) // 2
print(providerInt.value) // 3```

### Version 1.1.0

```let provider = Provider2<String, Int, Double> { "\(\$0) + \(\$1) = \(\$0 + \$1)" }

print(provider.value(10, 20.0)) // "10 + 20.0 = 30.0"```

Support 1, 2, 3, 4, 5 arguments count.

## Install

###### Via CocoaPods.

To install SwiftLazy with CocoaPods, add the following lines to your Podfile: `pod 'SwiftLazy'`

###### Via Carthage.

github "ivlevAstef/SwiftLazy" Swift (iOS8+,macOS10.10+,tvOS9+)

## Requirements

iOS 8.0+,macOS 10.10+,tvOS 9.0+; ARC; Swift >= 3.0