ankurp/Dollar.swift — pull request #28 by nubbel (2014-06-16 14:55:38+00:00)
Title: Make $.first and $.last generic functions.

Using `AnyObject` throws away any type information that is assigned to our data. Generics have many advantages:

- type safety: when you pass an array of integer to `$.first` you are guaranteed to get an `Int` back (or `nil`). Just from the signature the previous implementation would allow `$.first([1, 2])` to return a `String` (or anything else), because there's no relation of the return type to the input type.
- as a result you don't need to cast the return value of to the "expected type".
- numbers, enums, structs are no `AnyObject`s, only objects (class instances) are. I'm not sure why it was even possible to call `$.first` and `$.last` with an `Int` array. When I type `let arr: AnyObject[] = [1, 2]` in the playground I get an error.

We should use generics wherever possible. There are a lot more functions in Dollar that could benefit from them as well.

Btw. optionals are unwrapped with the `!` operator, not by casting them to the "unwrapped type". I needed to fix the `$.difference` function because it didn't work with the new generic `$.first` anymore.