diff --git a/endomorphism/generic/monoid.go b/endomorphism/generic/monoid.go index 9b8e0c6..8142075 100644 --- a/endomorphism/generic/monoid.go +++ b/endomorphism/generic/monoid.go @@ -28,6 +28,16 @@ func Of[ENDO ~func(A) A, F ~func(A) A, A any](f F) ENDO { } } +// Wrap converts any function to an [Endomorphism] +func Wrap[ENDO ~func(A) A, F ~func(A) A, A any](f F) ENDO { + return Of[ENDO](f) +} + +// Unwrap converts any [Endomorphism] to a normal function +func Unwrap[F ~func(A) A, ENDO ~func(A) A, A any](f ENDO) F { + return Of[F](f) +} + func Identity[ENDO ~func(A) A, A any]() ENDO { return Of[ENDO](F.Identity[A]) } diff --git a/endomorphism/monoid.go b/endomorphism/monoid.go index 8623692..4212f9b 100644 --- a/endomorphism/monoid.go +++ b/endomorphism/monoid.go @@ -29,6 +29,16 @@ func Of[F ~func(A) A, A any](f F) Endomorphism[A] { return G.Of[Endomorphism[A]](f) } +// Wrap converts any function to an [Endomorphism] +func Wrap[F ~func(A) A, A any](f F) Endomorphism[A] { + return G.Wrap[Endomorphism[A]](f) +} + +// Unwrap converts any [Endomorphism] to a function +func Unwrap[F ~func(A) A, A any](f Endomorphism[A]) F { + return G.Unwrap[F](f) +} + // Identity returns the identity [Endomorphism] func Identity[A any]() Endomorphism[A] { return G.Identity[Endomorphism[A]]()