// Copyright © 2015 GitHub. All rights reserved. public enum Cofree { indirect case Unroll(B, Syntax) public var unwrap: Syntax { switch self { case let .Unroll(_, rest): return rest } } } // MARK: - Comonad extension Cofree { var extract: B { switch self { case let .Unroll(b, _): return b } } func extend(transform: Cofree -> Other) -> Cofree { return .Unroll(transform(self), unwrap.map { $0.extend(transform) }) } }