Skip to content

Instantly share code, notes, and snippets.

@airspeedswift
Created November 29, 2014 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airspeedswift/d6798e3d1a6a7f79fcdf to your computer and use it in GitHub Desktop.
Save airspeedswift/d6798e3d1a6a7f79fcdf to your computer and use it in GitHub Desktop.
Weird Inference – narrowed down a bit
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