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:
12
json/json.go
12
json/json.go
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user