Skip to content

Commit ba31f86

Browse files
committed
LazyTagsResolver now supports parameter packs
1 parent 1c14836 commit ba31f86

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

Sources/Guise/Lazy/LazyTagsResolver+Async.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gregory Higley on 2022-09-29.
66
//
77

8+
#if swift(<5.9)
9+
810
public extension LazyTagsResolver {
911
func resolve<A1, A2>(
1012
args arg1: A1, _ arg2: A2
@@ -54,3 +56,5 @@ public extension LazyTagsResolver {
5456
try await resolve(args: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
5557
}
5658
}
59+
60+
#endif

Sources/Guise/Lazy/LazyTagsResolver+Async.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def args(items, fmt=lambda i: f'{i}', sep=', '):
1111
return sep.join(map(fmt, items))
1212
}%
1313

14+
#if swift(<5.9)
15+
1416
public extension LazyTagsResolver {
1517
% for a in range(2, arg_count + 1):
1618
func resolve<${args(range(1, a + 1), lambda i: f'A{i}')}>(
@@ -23,3 +25,5 @@ public extension LazyTagsResolver {
2325
% end
2426
% end
2527
}
28+
29+
#endif

Sources/Guise/Lazy/LazyTagsResolver+Sync.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gregory Higley on 2022-09-29.
66
//
77

8+
#if swift(<5.9)
9+
810
public extension LazyTagsResolver {
911
func resolve<A1, A2>(
1012
args arg1: A1, _ arg2: A2
@@ -54,3 +56,5 @@ public extension LazyTagsResolver {
5456
try resolve(args: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
5557
}
5658
}
59+
60+
#endif

Sources/Guise/Lazy/LazyTagsResolver+Sync.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def args(items, fmt=lambda i: f'{i}', sep=', '):
1111
return sep.join(map(fmt, items))
1212
}%
1313

14+
#if swift(<5.9)
15+
1416
public extension LazyTagsResolver {
1517
% for a in range(2, arg_count + 1):
1618
func resolve<${args(range(1, a + 1), lambda i: f'A{i}')}>(
@@ -23,3 +25,5 @@ public extension LazyTagsResolver {
2325
% end
2426
% end
2527
}
28+
29+
#endif

Sources/Guise/Lazy/LazyTagsResolver.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ public final class LazyTagsResolver<T> {
4646
self.resolver = resolver
4747
self.tags = tags
4848
}
49+
50+
#if swift(>=5.9)
51+
52+
public func resolve<A1, each A>(
53+
args arg1: A1 = (),
54+
_ args: repeat each A
55+
) throws -> T {
56+
let key = Key(T.self, tags: tags, args: (A1, repeat each A).self)
57+
guard let resolver else {
58+
throw ResolutionError(key: key, reason: .noResolver)
59+
}
60+
return try resolver.resolve(T.self, tags: tags, args: (arg1, repeat each args))
61+
}
62+
63+
public func resolve<A1, each A>(
64+
args arg1: A1 = (),
65+
_ args: repeat each A
66+
) async throws -> T {
67+
let key = Key(T.self, tags: tags, args: (A1, repeat each A).self)
68+
guard let resolver else {
69+
throw ResolutionError(key: key, reason: .noResolver)
70+
}
71+
return try await resolver.resolve(T.self, tags: tags, args: (arg1, repeat each args))
72+
}
73+
74+
#else
4975

5076
public func resolve<A>(args arg1: A = ()) throws -> T {
5177
let key = Key(T.self, tags: tags, args: A.self)
@@ -62,6 +88,8 @@ public final class LazyTagsResolver<T> {
6288
}
6389
return try await resolver.resolve(T.self, tags: tags, args: arg1)
6490
}
91+
92+
#endif
6593
}
6694

6795
extension LazyTagsResolver: LazyResolving {}

0 commit comments

Comments
 (0)