Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5.7 light touch adoption of some new features #59

Merged
merged 6 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
7 changes: 7 additions & 0 deletions Sources/Genything/AnyGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public struct AnyGenerator<T>: Generator {
wrappedNext = next
}

/// Creates an `AnyGenerator` which generates elements via the provided autoclosure
///
/// - Parameter next: A block which returns the next element
public init(_ next: @autoclosure @escaping () -> T) {
wrappedNext = { _ in next() }
}

/// Produces the next element from this generator using the provided random source
///
/// - Parameter randomSource: A source of random to be used by upstream generators
Expand Down
8 changes: 2 additions & 6 deletions Sources/Genything/Arbitrary/Type/Swift+Arbitrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,9 @@ extension LazySequence: Arbitrary where Base: Arbitrary {
extension Repeated: Arbitrary where Element: Arbitrary {
/// A generator of `Repeated`s where `Element` conforms to `Arbitrary`
public static var arbitrary: AnyGenerator<Repeated> {
let constructor: (Element, Int) -> Repeated<Element> = { element, count in
repeatElement(element, count: count)
}

return Element.arbitrary
Element.arbitrary
.zip(Int.arbitrary)
.map { t in constructor(t.0, t.1) }
.map(repeatElement(_:count:))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Genything/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// A Generators typically creates values using a `RandomSource`. If the `RandomSource` is not shared between multiple generators, then they are said to be independent e.g. One generator does not affect the randomness of any other generators.
///
/// - Note: The generator protocol has no requirement to be random nor is there any requirement to be stateless. The generator might generate random elements or follow some predetermined pattern. Therefore, sharing a generator between unrelated contexts should be done with care.
public protocol Generator {
public protocol Generator<T> {
/// The type of element which this Generator produces
associatedtype T
/// Produces the next element from this generator using the provided random source
Expand Down
2 changes: 1 addition & 1 deletion Sources/Genything/Operators/Generator+distinct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private struct FIFODistinctMemory<T: Equatable> {

private mutating func append(_ item: T) {
defer {
if let maxSize = maxSize, memory.count > maxSize {
if let maxSize, memory.count > maxSize {
memory.removeFirst()
}
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/Genything/Operators/Generator+map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ extension Generator {
public func map<R>(_ transform: @escaping (T) -> R) -> AnyGenerator<R> {
Generators.Map(source: self, transform: transform).eraseToAnyGenerator()
}



}

extension Generators {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Trickery/Fake+Emails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension Fake {

public static func business(_ name: String? = nil) -> AnyGenerator<String> {
let nameGen: AnyGenerator<String> = {
if let name = name {
if let name {
return Generators.constant(name).eraseToAnyGenerator()
}
return Fake.BusinessNames.any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Generator_DistinctTests: XCTestCase {
var last: Int? // Storage for the last bit we generated
testAllSatisfy(bitGenerator) { bit in
defer { last = bit } // Store the bit for the next comparison
if let last = last, last == bit {
if let last, last == bit {
// If this bit matches the last, the function does not work as expected
return false
}
Expand Down