pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
11.91k stars 1.37k forks source link

Deprecate `Shared`'s optional dynamic member lookup overload #3145

Closed stephencelis closed 1 month ago

stephencelis commented 1 month ago

Currently, Shared's dynamic member lookup is overloaded for convenience:

$shared                // Shared<Root>
$shared.value          // Shared<Value>
$shared.optionalValue  // Shared<Value>?

Unfortunately, this is also perhaps surprising, and goes against the grain when folks might expect to be handed a Shared<Value?>.

Also, there are times when you have a Shared<Value?> already, and you want to unwrap it. Dynamic member lookup doesn't help there (unless you know you can call $shared[dynamicMember: \.self]), and so you need a totally different operation to handle it:

if let unwrappedShared = Shared($optional) {
  // Do something with 'Shared<Value>'
}

So let's avoid this confusion in the future and focus on a single API for unwrapping shared values, which is the failable initializer that mirrors an API on Binding.