From c8234d27a4fbba98f281f82e5dbab50257492758 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 10:44:53 -0400 Subject: [PATCH] Document coiterate. --- prototype/Doubt/Cofree.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prototype/Doubt/Cofree.swift b/prototype/Doubt/Cofree.swift index 54fe26f4f..865af6502 100644 --- a/prototype/Doubt/Cofree.swift +++ b/prototype/Doubt/Cofree.swift @@ -21,6 +21,12 @@ public enum Cofree { self = Cofree>.coiterate { $0.out } (fix).map(annotate) } + + /// Constructs a cofree by coiteration. + /// + /// The initial seed is used as the annotation of the returned value. The continuation of the structure is unpacked by applying `annotate` to the seed and mapping the resulting syntax’s values recursively. In this manner, the structure is unfolded bottom-up, starting with `seed` and ending at the leaves. + /// + /// As this is the dual of `Free.iterate`, it’s unsurprising that we have a similar guarantee: coiteration is linear in the size of the constructed tree. public static func coiterate(annotate: B -> Syntax)(_ seed: B) -> Cofree { return .Unroll(seed, annotate(seed).map(coiterate(annotate))) }