diff --git a/endomorphism/endo.go b/endomorphism/endo.go new file mode 100644 index 0000000..9976c93 --- /dev/null +++ b/endomorphism/endo.go @@ -0,0 +1,60 @@ +// Copyright (c) 2023 IBM Corp. +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package endomorphism + +import ( + G "github.com/IBM/fp-go/endomorphism/generic" +) + +func MonadAp[A any](fab Endomorphism[A], fa A) A { + return G.MonadAp[Endomorphism[A]](fab, fa) +} + +func Ap[A any](fa A) func(Endomorphism[A]) A { + return G.Ap[Endomorphism[A]](fa) +} + +func MonadFlap[A any](fab Endomorphism[A], a A) A { + return G.MonadFlap[Endomorphism[A]](fab, a) +} + +func Flap[A any](a A) func(Endomorphism[A]) A { + return G.Flap[Endomorphism[A]](a) +} + +func MonadMap[A any](fa A, f Endomorphism[A]) A { + return G.MonadMap[Endomorphism[A]](fa, f) +} + +func Map[A any](f Endomorphism[A]) Endomorphism[A] { + return G.Map[Endomorphism[A]](f) +} + +func MonadChain[A any](ma A, f Endomorphism[A]) A { + return G.MonadChain[Endomorphism[A]](ma, f) +} + +func Chain[A any](f Endomorphism[A]) Endomorphism[A] { + return G.Chain[Endomorphism[A], A](f) +} + +func MonadChainFirst[A any](fa A, f Endomorphism[A]) A { + return G.MonadChainFirst[Endomorphism[A]](fa, f) +} + +func ChainFirst[A any](f Endomorphism[A]) Endomorphism[A] { + return G.ChainFirst[Endomorphism[A]](f) +} diff --git a/endomorphism/generic/endo.go b/endomorphism/generic/endo.go new file mode 100644 index 0000000..3a81337 --- /dev/null +++ b/endomorphism/generic/endo.go @@ -0,0 +1,60 @@ +// Copyright (c) 2023 IBM Corp. +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package generic + +import ( + I "github.com/IBM/fp-go/identity/generic" +) + +func MonadAp[GA ~func(A) A, A any](fab GA, fa A) A { + return I.MonadAp[GA, A, A](fab, fa) +} + +func Ap[GA ~func(A) A, A any](fa A) func(GA) A { + return I.Ap[GA, A, A](fa) +} + +func MonadFlap[GA ~func(A) A, A any](fab GA, a A) A { + return I.MonadFlap[GA, A, A](fab, a) +} + +func Flap[GA ~func(A) A, A any](a A) func(GA) A { + return I.Flap[GA, A, A](a) +} + +func MonadMap[GA ~func(A) A, A any](fa A, f GA) A { + return I.MonadMap[GA, A, A](fa, f) +} + +func Map[GA ~func(A) A, A any](f GA) GA { + return I.Map[GA, A, A](f) +} + +func MonadChain[GA ~func(A) A, A any](ma A, f GA) A { + return I.MonadChain[GA, A, A](ma, f) +} + +func Chain[GA ~func(A) A, A any](f GA) GA { + return I.Chain[GA, A](f) +} + +func MonadChainFirst[GA ~func(A) A, A any](fa A, f GA) A { + return I.MonadChainFirst[GA, A, A](fa, f) +} + +func ChainFirst[GA ~func(A) A, A any](f GA) GA { + return I.ChainFirst[GA, A, A](f) +}