Skip to content

Commit

Permalink
Merge pull request #9 from robrix/printable
Browse files Browse the repository at this point in the history
Printable
  • Loading branch information
robrix committed Nov 21, 2014
2 parents 7740504 + cc8f68c commit 5dafac7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Box/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// 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<T>: BoxType {
public final class Box<T>: BoxType, Printable {
/// Initializes a `Box` with the given value.
public init(_ value: T) {
self.value = value
Expand All @@ -16,4 +16,11 @@ public final class Box<T>: BoxType {
public func map<U>(f: T -> U) -> Box<U> {
return Box<U>(f(value))
}


// MARK: Printable

public var description: String {
return toString(value)
}
}
8 changes: 7 additions & 1 deletion Box/MutableBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// 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.
///
/// 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.
public final class MutableBox<T>: MutableBoxType {
public final class MutableBox<T>: MutableBoxType, Printable {
/// Initializes a `MutableBox` with the given value.
public init(_ value: T) {
self.value = value
Expand All @@ -18,4 +18,10 @@ public final class MutableBox<T>: MutableBoxType {
public func map<U>(f: T -> U) -> MutableBox<U> {
return MutableBox<U>(f(value))
}

// MARK: Printable

public var description: String {
return toString(value)
}
}

0 comments on commit 5dafac7

Please sign in to comment.