Created
November 29, 2014 01:37
-
-
Save airspeedswift/d6798e3d1a6a7f79fcdf to your computer and use it in GitHub Desktop.
Weird Inference – narrowed down a bit
This file contains hidden or 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
infix operator |> { | |
associativity left | |
} | |
func |><A,B>(a: A, f: A->B) -> B { | |
return f(a) | |
} | |
// this ought to be enough... | |
func reverse<D: CollectionType where D.Index : BidirectionalIndexType>(source: LazyRandomAccessCollection<D>) -> LazyBidirectionalCollection<RandomAccessReverseView<D>> { | |
return source.reverse() | |
} | |
func double(i: Int) -> Int { return i*2 } | |
// x is of type LazyBidirectionalCollection | |
let x = reverse(LazyRandomAccessCollection(1...10)) |> { $0.map(double) } | |
// y is of type [Int] | |
let y = reverse(lazy(1...10)) |> { $0.map(double) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment