1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 21:43:07 +03:00
semantic/prototype/Doubt/Cofree.swift

25 lines
355 B
Swift
Raw Normal View History

2015-10-14 16:34:18 +03:00
// Copyright © 2015 GitHub. All rights reserved.
2015-10-14 16:43:51 +03:00
public enum Cofree<A, B> {
2015-10-14 16:56:46 +03:00
indirect case Unroll(B, Syntax<Cofree, A>)
2015-10-14 16:59:04 +03:00
public var unwrap: Syntax<Cofree, A> {
switch self {
case let .Unroll(_, rest):
return rest
}
}
2015-10-14 16:34:18 +03:00
}
2015-10-14 16:43:23 +03:00
// MARK: - Comonad
extension Cofree {
var extract: B {
switch self {
2015-10-14 16:43:51 +03:00
case let .Unroll(b, _):
2015-10-14 16:43:23 +03:00
return b
}
}
}