From 6774213fcdb93f9c85847a91f78b3ad3bc8884c3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 10:09:38 -0400 Subject: [PATCH] Cofree is a Functor. --- prototype/Doubt/Cofree.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/prototype/Doubt/Cofree.swift b/prototype/Doubt/Cofree.swift index 33288bc9b..ff6d9aaab 100644 --- a/prototype/Doubt/Cofree.swift +++ b/prototype/Doubt/Cofree.swift @@ -12,6 +12,15 @@ public enum Cofree { } +// MARK: - Functor + +extension Cofree { + public func map(transform: B -> Other) -> Cofree { + return .Unroll(transform(extract), unwrap.map { $0.map(transform) }) + } +} + + // MARK: - Comonad extension Cofree {