// Copyright (c) 2014 Rob Rix. All rights reserved. /// Wraps a type `T` in a reference type. /// /// Typically this is used to work around limitations of value types (for example, the lack of codegen for recursive value types and type-parameterized enums with >1 case). It is also useful for sharing a single (presumably large) value without copying it. public final class Box: BoxType, CustomStringConvertible { /// Initializes a `Box` with the given value. public init(_ value: T) { self.value = value } /// Constructs a `Box` with the given `value`. public class func unit(_ value: T) -> Box { return Box(value) } /// The (immutable) value wrapped by the receiver. public let value: T /// Constructs a new Box by transforming `value` by `f`. public func map(_ f: (T) -> U) -> Box { return Box(f(value)) } // MARK: Printable public var description: String { return String(describing: value) } }