import Foundation


func _identityAsString(value: NSObject?) -> String {
    if value == nil {
        return "nil"
    }
    return NSString(format: "<%p>", value!)
}

func _arrayAsString<T>(items: [T], joiner: String = ", ") -> String {
    return items.reduce("") { accum, item in
        let prefix = (accum.isEmpty ? "" : joiner)
        return accum + prefix + "\(item)"
    }
}

@objc protocol NMBStringer {
    func NMB_stringify() -> String
}

func stringify<S: SequenceType>(value: S) -> String {
    var generator = value.generate()
    var strings = [String]()
    var value: S.Generator.Element?
    do {
        value = generator.next()
        if value != nil {
            strings.append(stringify(value))
        }
    } while value != nil
    let str = ", ".join(strings)
    return "[\(str)]"
}

extension NSArray : NMBStringer {
    func NMB_stringify() -> String {
        let str = self.componentsJoinedByString(", ")
        return "[\(str)]"
    }
}

func stringify<T>(value: T?) -> String {
    if value is Double {
        return NSString(format: "%.4f", (value as Double))
    }
    return toString(value)
}

import Foundation


func _identityAsString(value: NSObject?) -> String {
    if value == nil {
        return "nil"
    }
    return NSString(format: "<%p>", value!)
}

func _arrayAsString<T>(items: [T], joiner: String = ", ") -> String {
    return items.reduce("") { accum, item in
        let prefix = (accum.isEmpty ? "" : joiner)
        return accum + prefix + "\(item)"
    }
}

@objc protocol NMBStringer {
    func NMB_stringify() -> String
}

func stringify<S: SequenceType>(value: S) -> String {
    var generator = value.generate()
    var strings = [String]()
    var value: S.Generator.Element?
    do {
        value = generator.next()
        if value != nil {
            strings.append(stringify(value))
        }
    } while value != nil
    let str = ", ".join(strings)
    return "[\(str)]"
}

extension NSArray : NMBStringer {
    func NMB_stringify() -> String {
        let str = self.componentsJoinedByString(", ")
        return "[\(str)]"
    }
}

func stringify<T>(value: T) -> String {
    if value is Double {
        return NSString(format: "%.4f", (value as Double))
    }
    return toString(value)
}

func stringify<T>(value: T?) -> String {
    switch value {
    case let .Some(realValue):
        return stringify(realValue)
    default: return "nil"
    }
}

Fix output of matched values when tests fail.
Fix output of matched values when tests fail.

A previous commit removed the Printable extension on Optional types, since XCode 6.1/Swift 1.1 does not allow external types to have public extensions.

That extension made output of optionals clearer, and this commit restores that functionalityl.
