-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: common functions for endomorphism
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
- Loading branch information
1 parent
1d02f21
commit 6d043d2
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |