Skip to content

Commit

Permalink
fix: common functions for endomorphism
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
  • Loading branch information
CarstenLeue committed Dec 17, 2023
1 parent 1d02f21 commit 6d043d2
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
60 changes: 60 additions & 0 deletions endomorphism/endo.go
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)
}
60 changes: 60 additions & 0 deletions endomorphism/generic/endo.go
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)
}

0 comments on commit 6d043d2

Please sign in to comment.