title: An equivalent to computed properties using @Published in Swift Combine?
body: <p>In imperative Swift, it is common to use computed properties to provide convenient access to data without duplicating state. </p>
  
  <p>Let's say I have this class made for imperative MVC use:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class ImperativeUserManager {
      private(set) var currentUser: User? {
          didSet {
              if oldValue != currentUser {
                  NotificationCenter.default.post(name: NSNotification.Name("userStateDidChange"), object: nil)
                  // Observers that receive this notification might then check either currentUser or userIsLoggedIn for the latest state
              }
          }
      }
  
      var userIsLoggedIn: Bool {
          currentUser != nil
      }
  
      // ...
  }
  </code></pre>
  
  <p>If I want to create a reactive equivalent with Combine, e.g. for use with SwiftUI, I can easily add <code>@Published</code> to stored properties to generate <code>Publisher</code>s, but not for computed properties. </p>
  
  <pre class="lang-swift prettyprint-override"><code>    @Published var userIsLoggedIn: Bool { // Error: Property wrapper cannot be applied to a computed property
          currentUser != nil
      }
  </code></pre>
  
  <p>There are various workarounds I could think of. I could make my computed property stored instead and keep it updated. </p>
  
  <p>Option 1: Using a property observer:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class ReactiveUserManager1: ObservableObject {
      @Published private(set) var currentUser: User? {
          didSet {
              userIsLoggedIn = currentUser != nil
          }
      }
  
      @Published private(set) var userIsLoggedIn: Bool = false
  
      // ...
  }
  </code></pre>
  
  <p>Option 2: Using a <code>Subscriber</code> in my own class:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class ReactiveUserManager2: ObservableObject {
      @Published private(set) var currentUser: User?
      @Published private(set) var userIsLoggedIn: Bool = false
  
      private var subscribers = Set&lt;AnyCancellable&gt;()
  
      init() {
          $currentUser
              .map { $0 != nil }
              .assign(to: \.userIsLoggedIn, on: self)
              .store(in: &amp;subscribers)
      }
  
      // ...
  }
  </code></pre>
  
  <p>However, these workarounds are not as elegant as computed properties. They duplicate state and they do not update both properties simultaneously. </p>
  
  <p>What would be a proper equivalent to adding a <code>Publisher</code> to a computed property in Combine?</p>