private func comparableAttributes<T, U:Equatable>(first f:T, second s:T)->(T->U) -> U?{
return { trans in
let x = trans(f)
let y = trans(s)
return (x == y) ? nil : x
}
}
If i do this it doesnt work...
let comparitor = comparableAttributes(first: paragraph, second: defaultParagraph)
error:cannot invoke 'comparableAttributes with argument list of type
(first:NSParagraphStyle, second:NSParagraphStyle)`*
this is what I want to do
let comparitor = comparableAttributes(first: paragraph, second: defaultParagraph)
self.headIndent = comparitor{$0.headIndent}
self.tailIndent = comparitor{$0.tailIndent}
to replace this..
//self.headIndent = (paragraph.headIndent == defaultParagraph.headIndent) ? nil : Float(paragraph.headIndent)
//self.tailIndent = (paragraph.tailIndent == defaultParagraph.tailIndent) ? nil : Float(paragraph.tailIndent)
I CAN do this:
let comparitor = comparableAttributes(first: paragraph, second: defaultParagraph)({ $0.alignment })
It appears that the curried function needs to establish all of the generic types in the first set of function parameters.
So testing this out further, the generics will work with currying if all of the generic types are established before getting to the second function. In the example above, the closure returned is not able to establish the type U. For instance a function that looks like this works fine:
func <T, U:Equatable>(T->U) -> (first f:T, second s:T) -> U?