1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-25 22:21:49 +02:00

fix: remove unnecesary indirection in E.TryCatch

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-10-23 08:25:45 +02:00
parent 83a0c6cdef
commit 08d9fed9af
34 changed files with 11163 additions and 11528 deletions

View File

@@ -23,16 +23,12 @@ import (
// Unmarshal parses a JSON data structure from bytes
func Unmarshal[A any](data []byte) E.Either[error, A] {
return E.TryCatchError(func() (A, error) {
var result A
err := json.Unmarshal(data, &result)
return result, err
})
var result A
err := json.Unmarshal(data, &result)
return E.TryCatchError(result, err)
}
// Marshal converts a data structure to json
func Marshal[A any](a A) E.Either[error, []byte] {
return E.TryCatchError(func() ([]byte, error) {
return json.Marshal(a)
})
return E.TryCatchError(json.Marshal(a))
}