Last active
February 10, 2017 05:16
-
-
Save mayoff/f11fb7d75bd6bd5ba835c925b335b635 to your computer and use it in GitHub Desktop.
Avoiding duplication of property names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For https://twitter.com/nicklockwood/status/819938181483233285 | |
protocol Withable { | |
init() | |
} | |
extension Withable { | |
func with(_ body: (inout Self) -> ()) -> Self { | |
var copy = self | |
body(©) | |
return copy | |
} | |
init(_ body: (inout Self) -> ()) { | |
self.init() | |
body(&self) | |
} | |
} | |
public enum WrapMode { case disabled, beforeFirst } | |
public enum IndentMode { case indent } | |
public struct FormatOptions { | |
public var indent = " " | |
public var linebreak = "\n" | |
public var allowInlineSemicolons = true | |
public var spaceAroundRangeOperators = true | |
public var useVoid = true | |
public var trailingCommas = true | |
public var trailingClosures = false | |
public var indentComments = true | |
public var truncateBlankLines = true | |
public var insertBlankLines = true | |
public var removeBlankLines = true | |
public var allmanBraces = false | |
public var stripHeader = false | |
public var ifdefIndent = IndentMode.indent | |
public var wrapArguments = WrapMode.disabled | |
public var wrapElements = WrapMode.beforeFirst | |
public var uppercaseHex = true | |
public var experimentalRules = false | |
public var fragment = false | |
} | |
extension FormatOptions: Withable { } | |
let options1 = FormatOptions { $0.fragment = true; $0.wrapArguments = .beforeFirst } | |
let options2 = options1.with({ $0.uppercaseHex = false; $0.trailingCommas = false }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment