# Cofree

``public final class Cofree<F, A> : CofreeOf<F, A> where F : Functor``

Cofree is a type that, given any Functor, is able to provide a Comonad instance, that can be interpreted into a more restrictive one.

• ``` head ```

First value wrapped in this comonad.

#### Declaration

Swift

``public let head: A``
• ``` tail ```

A potentially lazy way of obtaining further values in this comonadic structure.

#### Declaration

Swift

``public let tail: Eval<Kind<F, Cofree<F, A>>>``
• ``` fix(_:) ```

Safe downcast.

#### Declaration

Swift

``public static func fix(_ fa: CofreeOf<F, A>) -> Cofree<F, A>``

#### Parameters

 ``` fa ``` Value in the higher-kind form.

#### Return Value

Value cast to Cofree.

• ``` init(_:_:) ```

Initializes a Cofree value.

#### Declaration

Swift

``public init(_ head: A, _ tail: Eval<Kind<F, Cofree<F, A>>>)``

#### Parameters

 ``` head ``` Value to be wrapped. ``` tail ``` A description of the potential values in the comonadic context.
• ``` tailForced() ```

Obtains the values in the context of this Cofree comonad.

#### Declaration

Swift

``public func tailForced() -> Kind<F, Cofree<F, A>>``

#### Return Value

The result of evaluating the tail of this Cofree.

• ``` unfold(_:_:) ```

Constructs a Cofree from a seed and an unfolding function.

#### Declaration

Swift

``````public static func unfold(
_ a: A,
_ f: @escaping (A) -> Kind<F, A>
) -> Cofree<F, A>``````

#### Parameters

 ``` a ``` Seed. ``` f ``` Unfolding function.

#### Return Value

A Cofree value resulting from the unfolding process.

• ``` create(_:_:) ```

Constructs a Cofree from a seed and an unfolding function.

#### Declaration

Swift

``````public static func create(
_ a: A,
_ f: @escaping (A) -> Kind<F, A>
) -> Cofree<F, A>``````

#### Parameters

 ``` a ``` Seed. ``` f ``` Unfolding function.

#### Return Value

A Cofree value resulting from the unfolding process.

• ``` cata(_:) ```

Folds this structure into a single value.

#### Declaration

Swift

``func cata<B>(_ folder: @escaping (A, Kind<F, B>) -> Eval<B>) -> Eval<B>``

#### Parameters

 ``` folder ``` Folding function to collapse this structure.

#### Return Value

Result from the folding process.

• ``` cataM(_:_:) ```

Folds this structure into a monadic value.

#### Declaration

Swift

``````func cataM<B, M: Monad>(
_ folder: @escaping (A, Kind<F, B>) -> Kind<M, B>,
_ inclusion: FunctionK<ForEval, M>
) -> Kind<M, B>``````

#### Parameters

 ``` folder ``` Folding function to collaps this structure. ``` inclusion ``` A natural transformation into the target Monad.

#### Return Value

A value in the new monadic context.