Set a variable to the < (“less than”) operator as a function in Swift?

There's a neat guide here about overloading operators in Swift, but it doesn't say anything about treating operators as functions that I can pass around as variables like any other function. I want to do something like var comparator = (<) to set a variable to the < function, but every syntax I've tried hasn't worked, and the Swift Programming Guide doesn't mention anything relevant. I know how to achieve a similar effect with a lambda expression, but that's messy. How can I set a variable to the < function?


If you give comparator an explicit type, then it will work.

var comparator:(Int,Int)->Bool = (<)


var comparator:(Double,Double)->Bool = (<)

Less than < isn't a single function, but a whole collection of them for different types. By identifying the type you are interested in comparing, you allow the compiler to select the correct less than function.

Need Your Help

css - embed font both for IE and FF

css font-face

I'm trying to embed a font, the problem is that it is just displayed in Firefox but not with Internet Explorer.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.