Endo
Endo is a Monoid that will combine (2) functions that have matching domains
and codomains (endofunctions) under function composition. Due to the nature
of Endo wrapping a function, the underlying value can either be extracted
using valueOf like any other Monoid or can be executed directly
using runWith, supplying the input.
- Source
- Runkit
Implements#
Semigroup, Monoid
Construction#
Endo is constructed by passing the constructor an Endomorphism, which is a
function in which the domain/codomain (src/target) are of the same
type. For example a function that is String -> String.
There is no type checking on the provided function, so some discipline on the
part of the user is required to make sure the proper type is being used on in
all cases. This can be partly mitigated by using an Endomorphism of the
type Maybe a. Then the supplied functions could do type checking and
return Nothing if the types do not match up.
- Source
- Runkit
Constructor Methods#
empty#
empty provides the identity for the Monoid in that when the value it
provides is concated to any other value, it will return the other value. In
the case of Endo the result of empty is the identity function, which echoes
its input. empty is available on both the Constructor and the Instance for
convenience.
- Source
- Runkit
Instance Methods#
concat#
concat is used to combine (2) Semigroups of the same type under an operation
specified by the Semigroup. In the case of Endo, it will combine (2)
endofunctions under function composition.
- Source
- Runkit
valueOf#
valueOf is used on all crocks Monoids as a means of extraction. While the
extraction is available, types that implement valueOf are not necessarily
a Comonad. This function is used primarily for convenience for some of the
helper functions that ship with crocks. Calling valueOf on
an Endo instance will result in the underlying endofunction.
- Source
- Runkit
runWith#
Endo wraps a function and as such, its underlying endofunction can be run
while inside of an Endo by calling runWith. Providing a valid value of the
same type required by the function, runWith will execute the underlying
function and return the result.
- Source
- Runkit