From 18294049791b461752df70a6fa38ababac4da8bf Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 28 Sep 2015 22:12:08 -0400 Subject: [PATCH] `fits` is a method. --- prototype/Doubt/Doc.swift | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/prototype/Doubt/Doc.swift b/prototype/Doubt/Doc.swift index a0ba2ad9f..a0367d3fb 100644 --- a/prototype/Doubt/Doc.swift +++ b/prototype/Doubt/Doc.swift @@ -13,6 +13,16 @@ public enum Doc: CustomStringConvertible, Equatable { return "\n" + String(count: n, repeatedValue: " " as Character) + doc.description } } + + public func fits(width: Int) -> Bool { + guard width >= 0 else { return false } + switch self { + case .Empty, .Line: + return true + case let .Text(s, x): + return x.fits(width - Int(s.characters.count)) + } + } } public enum DOC { @@ -107,21 +117,11 @@ func be(w: Int, _ k: Int, _ z: Stream<(Int, DOC)>) -> Doc { } func better(w: Int, _ k: Int, _ x: Doc, _ y: Doc) -> Doc { - return fits(w - k, x) + return x.fits(w - k) ? x : y } -func fits(w: Int, _ x: Doc) -> Bool { - guard w >= 0 else { return false } - switch x { - case .Empty, .Line: - return true - case let .Text(s, x): - return fits(w - Int(s.characters.count), x) - } -} - public protocol CustomDocConvertible: CustomStringConvertible { var doc: DOC { get }