Created
September 4, 2015 12:17
-
-
Save oisdk/50c84bb59fb71f306cf0 to your computer and use it in GitHub Desktop.
This file contains 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
protocol NListType : SequenceType { | |
typealias Element | |
init() | |
var ar: [Element] { get } | |
} | |
extension NListType { | |
func generate() -> IndexingGenerator<[Element]> { | |
return ar.generate() | |
} | |
var count: Int { return ar.count } | |
} | |
struct Empty<Element> : NListType { | |
init() {} | |
let ar: [Element] = [] | |
} | |
struct NList<Element, Tail: NListType where Tail.Element == Element> : NListType { | |
init(_ head: Element, _ tail: Tail = Tail()) { | |
self.tail = tail | |
self.head = head | |
} | |
init() { fatalError() } | |
var ar: [Element] { return [head] + tail.ar } | |
let tail: Tail | |
let head: Element | |
} | |
infix operator |> { associativity right precedence 90 } | |
func |><E, L : NListType where L.Element == E>(lhs: E, rhs: L) -> NList<E, L> { | |
return NList(lhs, rhs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment