Skip to content

Commit 05e5188

Browse files
committed
lil upd Stored
1 parent 5705726 commit 05e5188

1 file changed

Lines changed: 51 additions & 4 deletions

File tree

Source/Stored.swift

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import Combine
22
import Foundation
33

44
/// A property wrapper that forwards reads and writes to a storage backend.
5-
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
65
@propertyWrapper
7-
public struct Stored<Value> {
6+
public struct Stored<Value: Equatable> {
87
private let base: AnyStorage<Value>
98

109
/// The current value from the underlying storage.
@@ -39,10 +38,58 @@ public struct Stored<Value> {
3938
/// Creates a wrapper that synchronizes multiple storages.
4039
///
4140
/// - Parameter base: Storages to combine into one synchronized storage.
42-
public init(storages base: [any Storage<Value>]) throws
43-
where Value: ExpressibleByNilLiteral & Equatable {
41+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
42+
public init(storages base: [any Storage<Value>], defaultValue: Value) throws {
43+
self.base = try zip(storages: base, defaultValue: defaultValue).toAny()
44+
}
45+
46+
public init(storages: [AnyStorage<Value>], defaultValue: Value) throws {
47+
self.base = try StorageComposition(storages: storages, defaultValue: defaultValue).toAny()
48+
}
49+
}
50+
51+
public extension Stored where Value: ExpressibleByNilLiteral {
52+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
53+
init(storages base: [any Storage<Value>]) throws {
54+
self.base = try zip(storages: base).toAny()
55+
}
56+
57+
init(storages: [AnyStorage<Value>]) throws {
58+
self.base = try StorageComposition(storages: storages).toAny()
59+
}
60+
}
61+
62+
public extension Stored where Value: ExpressibleByArrayLiteral {
63+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
64+
init(storages base: [any Storage<Value>]) throws {
65+
self.base = try zip(storages: base).toAny()
66+
}
67+
68+
init(storages: [AnyStorage<Value>]) throws {
69+
self.base = try StorageComposition(storages: storages).toAny()
70+
}
71+
}
72+
73+
public extension Stored where Value: ExpressibleByDictionaryLiteral {
74+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
75+
init(storages base: [any Storage<Value>]) throws {
4476
self.base = try zip(storages: base).toAny()
4577
}
78+
79+
init(storages: [AnyStorage<Value>]) throws {
80+
self.base = try StorageComposition(storages: storages).toAny()
81+
}
82+
}
83+
84+
public extension Stored where Value: ExpressibleByBooleanLiteral {
85+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
86+
init(storages base: [any Storage<Value>]) throws {
87+
self.base = try zip(storages: base).toAny()
88+
}
89+
90+
init(storages: [AnyStorage<Value>]) throws {
91+
self.base = try StorageComposition(storages: storages).toAny()
92+
}
4693
}
4794

4895
#if swift(>=6.0)

0 commit comments

Comments
 (0)