// Copyright (c) 2014 Rob Rix. All rights reserved. /// Wraps a type `T` in a mutable reference type. /// /// While this, like `Box` could be used to work around limitations of value types, it is much more useful for sharing a single mutable value such that mutations are shared. /// /// As with all mutable state, this should be used carefully, for example as an optimization, rather than a default design choice. Most of the time, `Box` will suffice where any `BoxType` is needed. public final class MutableBox: MutableBoxType, CustomStringConvertible { /// Initializes a `MutableBox` with the given value. public init(_ value: T) { self.value = value } /// The (mutable) value wrapped by the receiver. public var value: T /// Constructs a new MutableBox by transforming `value` by `f`. public func map(_ f: (T) -> U) -> MutableBox { return MutableBox(f(value)) } // MARK: Printable public var description: String { return String(describing: value) } }