mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-29 22:38:29 +02:00
fix: add ioeither
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
22
json/type.go
Normal file
22
json/type.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
E "github.com/ibm/fp-go/either"
|
||||
F "github.com/ibm/fp-go/function"
|
||||
O "github.com/ibm/fp-go/option"
|
||||
)
|
||||
|
||||
func ToTypeE[A any](src any) E.Either[error, A] {
|
||||
return F.Pipe2(
|
||||
src,
|
||||
Marshal[any],
|
||||
E.Chain(Unmarshal[A]),
|
||||
)
|
||||
}
|
||||
|
||||
func ToTypeO[A any](src any) O.Option[A] {
|
||||
return F.Pipe1(
|
||||
ToTypeE[A](src),
|
||||
E.ToOption[error, A](),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user