Skip to content

Commit 7036839

Browse files
committed
DRY
1 parent ff8deb0 commit 7036839

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

StandardLibrary/StandardLibrary.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ private let freestandingLibrarySourceRoot = hostedLibrarySourceRoot.appendingPat
3838

3939
extension Utils.Host {
4040

41+
/// Returns an AST representing the given standard library `variant` (either `"freestanding"` or
42+
/// `"hosted"`), conditionally compiled for targeting the host platform.
43+
private static func libraryAST(_ variant: String) -> Result<AST, Error> {
44+
Result {
45+
try CBORDecoder().forAST.decode(
46+
AST.self,
47+
from: Data(
48+
contentsOf: resource(variant, withExtension: "cbor"),
49+
options: .alwaysMapped))
50+
}
51+
}
52+
4153
/// An AST representing the whole standard library, conditionally compiled for targeting the host
4254
/// platform.
43-
public static let hostedLibraryAST = Result {
44-
try CBORDecoder().forAST.decode(
45-
AST.self,
46-
from: Data(
47-
contentsOf: resource("hosted", withExtension: "cbor"),
48-
options: .alwaysMapped))
49-
}
55+
public static let hostedLibraryAST: Result<AST, Error> = libraryAST("hosted")
5056

5157
/// An AST representing the freestanding core of standard library, conditionally compiled for
5258
/// targeting the host platform.
53-
public static let freestandingLibraryAST = Result {
54-
try CBORDecoder().forAST.decode(
55-
AST.self,
56-
from: Data(
57-
contentsOf: resource("freestanding", withExtension: "cbor"),
58-
options: .alwaysMapped))
59-
}
59+
public static let freestandingLibraryAST: Result<AST, Error> = libraryAST("freestanding")
6060

6161
}

0 commit comments

Comments
 (0)