Created
March 2, 2016 23:05
-
-
Save alonecuzzo/a543ce0f2fd270051f00 to your computer and use it in GitHub Desktop.
Some notes for sals cr
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
var str = "Hello, playground" | |
protocol TestProtocol { | |
typealias T | |
} | |
protocol AnotherProtocol {} | |
extension TestProtocol where Self.T == String {} | |
protocol Concatenable { | |
typealias T | |
func concatenate(lhs: T, conjunction: T, rhs: T?) -> T | |
} | |
extension Concatenable where Self.T == String { | |
func concatenate(lhs: T, conjunction: T, rhs: T?) -> T { | |
guard let rhs = rhs else { return lhs } | |
if rhs.characters.count == 0 { return rhs } | |
return lhs | |
} | |
} | |
struct StringConcatenator: Concatenable { | |
typealias T = String | |
} | |
let x = StringConcatenator().concatenate("left", conjunction: "+", rhs: "right") | |
x |
look at concatenation in other libraries, maybe that string helper class, but then we'd want something for array
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was thinking of creating a concatenatable protocol and extending it with generic constraints, depending on the generic type, you could have default implementations of the concatenate function.
I still would like an extension on string, and maybe some custom operators.
"mystring".concat("+", nil)