-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: expose Monad and Pointed for IOEither
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
- Loading branch information
1 parent
6ab6ff0
commit 65e09e0
Showing
2 changed files
with
88 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,56 @@ | ||
// Copyright (c) 2024 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 ( | ||
ET "github.com/IBM/fp-go/either" | ||
"github.com/IBM/fp-go/internal/monad" | ||
"github.com/IBM/fp-go/internal/pointed" | ||
) | ||
|
||
type ioEitherPointed[E, A any, GA ~func() ET.Either[E, A]] struct{} | ||
|
||
type ioEitherMonad[E, A, B any, GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B]] struct{} | ||
|
||
func (o *ioEitherPointed[E, A, GA]) Of(a A) GA { | ||
return Of[GA, E, A](a) | ||
} | ||
|
||
func (o *ioEitherMonad[E, A, B, GA, GB, GAB]) Of(a A) GA { | ||
return Of[GA, E, A](a) | ||
} | ||
|
||
func (o *ioEitherMonad[E, A, B, GA, GB, GAB]) Map(f func(A) B) func(GA) GB { | ||
return Map[GA, GB, E, A, B](f) | ||
} | ||
|
||
func (o *ioEitherMonad[E, A, B, GA, GB, GAB]) Chain(f func(A) GB) func(GA) GB { | ||
return Chain[GA, GB, E, A, B](f) | ||
} | ||
|
||
func (o *ioEitherMonad[E, A, B, GA, GB, GAB]) Ap(fa GA) func(GAB) GB { | ||
return Ap[GB, GAB, GA, E, A, B](fa) | ||
} | ||
|
||
// Pointed implements the pointed operations for [IOEither] | ||
func Pointed[E, A any, GA ~func() ET.Either[E, A]]() pointed.Pointed[A, GA] { | ||
return &ioEitherPointed[E, A, GA]{} | ||
} | ||
|
||
// Monad implements the monadic operations for [IOEither] | ||
func Monad[E, A, B any, GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B]]() monad.Monad[A, B, GA, GB, GAB] { | ||
return &ioEitherMonad[E, A, B, GA, GB, GAB]{} | ||
} |
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,32 @@ | ||
// Copyright (c) 2024 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 ioeither | ||
|
||
import ( | ||
"github.com/IBM/fp-go/internal/monad" | ||
"github.com/IBM/fp-go/internal/pointed" | ||
G "github.com/IBM/fp-go/ioeither/generic" | ||
) | ||
|
||
// Pointed returns the pointed operations for [IOEither] | ||
func Pointed[E, A any]() pointed.Pointed[A, IOEither[E, A]] { | ||
return G.Pointed[E, A, IOEither[E, A]]() | ||
} | ||
|
||
// Monad returns the monadic operations for [IOEither] | ||
func Monad[E, A, B any]() monad.Monad[A, B, IOEither[E, A], IOEither[E, B], IOEither[E, func(A) B]] { | ||
return G.Monad[E, A, B, IOEither[E, A], IOEither[E, B], IOEither[E, func(A) B]]() | ||
} |