mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: add Wrap and Unwrap to endomorphism
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -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])
|
||||
}
|
||||
|
@@ -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]]()
|
||||
|
Reference in New Issue
Block a user