Last active
December 20, 2015 05:53
-
-
Save JessyCatterwaul/b37f3e2bafeeeef3d25c to your computer and use it in GitHub Desktop.
This file contains 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
enum StringPaddingStyle {case Left, Right} | |
func padStringToLength( | |
sourceString: String, | |
destinationCount: Int, | |
paddingStyle: StringPaddingStyle = .Left, | |
paddingCharacter: Character = " " | |
) -> String { | |
let padCount = destinationCount - sourceString.characters.count, | |
padString = String(count: padCount, repeatedValue: paddingCharacter) | |
return paddingStyle == .Left ? padString + sourceString | |
: sourceString + padString | |
} | |
func elongatedToShowRationaleForShortcuts( | |
sourceString: String, | |
destinationCount: Int, | |
paddingStyle: StringPaddingStyle = .Left, | |
paddingCharacter: Character = " " | |
) -> String { | |
let standsAlone = "" | |
let | |
standsAlone1 = "", | |
standsAlone2 = "", | |
standsAlone3 = "" | |
let isUsedAgainInThisList = "", | |
reliesOnIsUsedInThisList = isUsedAgainInThisList, | |
andThisAlsoRelies = isUsedAgainInThisList | |
let padCount = destinationCount - sourceString.characters.count, | |
padString = String(count: padCount, repeatedValue: paddingCharacter) | |
return { | |
if paddingStyle == .Left {return padString + sourceString} | |
else {return sourceString + padString} | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"CURRY" is actually the curry emoji, but Gist comments don't support emoji. Actual code is here: https://github.com/Jessy-/Euler/blob/master/Euler_Metal/EulerProblem.swift
I think adding an empty line after the constants upon which others depend is good, unless only one constant is dependent:
I thought that I had a good example of how I've used more dependent "combined lets"…
...but I actually do it like this now:
There is consistency in how far in those parameter or constant names are indented, though.