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

Document coiterate.

This commit is contained in:
Rob Rix 2015-10-14 10:44:53 -04:00
parent c13023b85b
commit c8234d27a4

View File

@ -21,6 +21,12 @@ public enum Cofree<A, B> {
self = Cofree<A, Fix<A>>.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 syntaxs 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`, its unsurprising that we have a similar guarantee: coiteration is linear in the size of the constructed tree.
public static func coiterate(annotate: B -> Syntax<B, A>)(_ seed: B) -> Cofree {
return .Unroll(seed, annotate(seed).map(coiterate(annotate)))
}