Skip to content

Commit 5dafac7

Browse files
author
Rob Rix
committed
Merge pull request #9 from robrix/printable
Printable
2 parents 7740504 + cc8f68c commit 5dafac7

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

Box/Box.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// Wraps a type `T` in a reference type.
44
///
55
/// 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.
6-
public final class Box<T>: BoxType {
6+
public final class Box<T>: BoxType, Printable {
77
/// Initializes a `Box` with the given value.
88
public init(_ value: T) {
99
self.value = value
@@ -16,4 +16,11 @@ public final class Box<T>: BoxType {
1616
public func map<U>(f: T -> U) -> Box<U> {
1717
return Box<U>(f(value))
1818
}
19+
20+
21+
// MARK: Printable
22+
23+
public var description: String {
24+
return toString(value)
25+
}
1926
}

Box/MutableBox.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// While this, like `Box<T>` 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.
66
///
77
/// 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<T>` will suffice where any `BoxType` is needed.
8-
public final class MutableBox<T>: MutableBoxType {
8+
public final class MutableBox<T>: MutableBoxType, Printable {
99
/// Initializes a `MutableBox` with the given value.
1010
public init(_ value: T) {
1111
self.value = value
@@ -18,4 +18,10 @@ public final class MutableBox<T>: MutableBoxType {
1818
public func map<U>(f: T -> U) -> MutableBox<U> {
1919
return MutableBox<U>(f(value))
2020
}
21+
22+
// MARK: Printable
23+
24+
public var description: String {
25+
return toString(value)
26+
}
2127
}

0 commit comments

Comments
 (0)