mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-23 22:14:53 +02:00
fix: reformat
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -4,10 +4,9 @@
|
||||
|
||||
package io
|
||||
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/v2/tuple"
|
||||
"github.com/IBM/fp-go/v2/internal/apply"
|
||||
"github.com/IBM/fp-go/v2/tuple"
|
||||
)
|
||||
|
||||
// SequenceT1 converts 1 [IO[T]] into a [IO[tuple.Tuple1[T1]]]
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
package ioeither
|
||||
|
||||
|
||||
import (
|
||||
G "github.com/IBM/fp-go/v2/ioeither/generic"
|
||||
"github.com/IBM/fp-go/v2/internal/apply"
|
||||
G "github.com/IBM/fp-go/v2/ioeither/generic"
|
||||
"github.com/IBM/fp-go/v2/tuple"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// 2025-03-04 23:59:33.8343102 +0100 CET m=+0.003180601
|
||||
package generic
|
||||
|
||||
|
||||
import (
|
||||
ET "github.com/IBM/fp-go/v2/either"
|
||||
)
|
||||
@@ -14,7 +13,8 @@ func Eitherize0[GIOA ~func() ET.Either[error, R], F ~func() (R, error), R any](f
|
||||
return func() GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e()
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GIOA]
|
||||
@@ -30,7 +30,8 @@ func Eitherize1[GIOA ~func() ET.Either[error, R], F ~func(T1) (R, error), T1, R
|
||||
return func(t1 T1) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [GIOA]
|
||||
@@ -46,7 +47,8 @@ func Eitherize2[GIOA ~func() ET.Either[error, R], F ~func(T1, T2) (R, error), T1
|
||||
return func(t1 T1, t2 T2) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [GIOA]
|
||||
@@ -62,7 +64,8 @@ func Eitherize3[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3) (R, error)
|
||||
return func(t1 T1, t2 T2, t3 T3) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [GIOA]
|
||||
@@ -78,7 +81,8 @@ func Eitherize4[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4) (R, er
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [GIOA]
|
||||
@@ -94,7 +98,8 @@ func Eitherize5[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5) (R
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4, t5)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [GIOA]
|
||||
@@ -110,7 +115,8 @@ func Eitherize6[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4, t5, t6)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [GIOA]
|
||||
@@ -126,7 +132,8 @@ func Eitherize7[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4, t5, t6, t7)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [GIOA]
|
||||
@@ -142,7 +149,8 @@ func Eitherize8[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4, t5, t6, t7, t8)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [GIOA]
|
||||
@@ -158,7 +166,8 @@ func Eitherize9[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [GIOA]
|
||||
@@ -174,7 +183,8 @@ func Eitherize10[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10) GIOA {
|
||||
return func() ET.Either[error, R] {
|
||||
return e(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uneitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [GIOA]
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
package iooption
|
||||
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/v2/tuple"
|
||||
"github.com/IBM/fp-go/v2/internal/apply"
|
||||
"github.com/IBM/fp-go/v2/tuple"
|
||||
)
|
||||
|
||||
// SequenceT1 converts 1 [IOOption[T]] into a [IOOption[tuple.Tuple1[T1]]]
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestMultipleHttpRequests(t *testing.T) {
|
||||
assert.Equal(t, E.Of[error](count), result())
|
||||
}
|
||||
|
||||
func heterogeneousHTTPRequests() R.ReaderIOEither[T.Tuple2[PostItem, CatFact]] {
|
||||
func heterogeneousHTTPRequests() ReaderIOEither[T.Tuple2[PostItem, CatFact]] {
|
||||
// prepare the http client
|
||||
client := H.MakeClient(HTTP.DefaultClient)
|
||||
// readSinglePost sends a GET request and parses the response as [PostItem]
|
||||
|
||||
24
v2/samples/http/types.go
Normal file
24
v2/samples/http/types.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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 http
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/v2/context/readerioeither"
|
||||
)
|
||||
|
||||
type (
|
||||
ReaderIOEither[A any] = readerioeither.ReaderIOEither[A]
|
||||
)
|
||||
@@ -108,7 +108,7 @@ var (
|
||||
checkActive = E.FromPredicate(Chapter08User.isActive, F.Constant1[Chapter08User](fmt.Errorf("your account is not active")))
|
||||
|
||||
// validateUser :: (User -> Either String ()) -> User -> Either String User
|
||||
validateUser = F.Curry2(func(validate func(Chapter08User) E.Either[error, any], user Chapter08User) E.Either[error, Chapter08User] {
|
||||
validateUser = F.Curry2(func(validate func(Chapter08User) Either[any], user Chapter08User) Either[Chapter08User] {
|
||||
return F.Pipe2(
|
||||
user,
|
||||
validate,
|
||||
@@ -117,7 +117,7 @@ var (
|
||||
})
|
||||
|
||||
// save :: User -> IOEither error User
|
||||
save = func(user Chapter08User) IOE.IOEither[error, Chapter08User] {
|
||||
save = func(user Chapter08User) IOEither[Chapter08User] {
|
||||
return IOE.FromIO[error](func() Chapter08User {
|
||||
var u = user
|
||||
u.Saved = true
|
||||
@@ -126,7 +126,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func Withdraw(amount float32) func(account Account) O.Option[Account] {
|
||||
func Withdraw(amount float32) func(account Account) Option[Account] {
|
||||
|
||||
return F.Flow3(
|
||||
getBalance,
|
||||
@@ -151,7 +151,7 @@ func MakeUser(d string) User {
|
||||
|
||||
var parseDate = F.Bind1of2(E.Eitherize2(time.Parse))(time.DateOnly)
|
||||
|
||||
func GetAge(now time.Time) func(User) E.Either[error, float64] {
|
||||
func GetAge(now time.Time) func(User) Either[float64] {
|
||||
return F.Flow3(
|
||||
getBirthDate,
|
||||
parseDate,
|
||||
|
||||
@@ -61,8 +61,8 @@ var (
|
||||
}
|
||||
|
||||
// getFromCache :: String -> IO User
|
||||
getFromCache = func(name string) IOO.IOOption[Player] {
|
||||
return func() O.Option[Player] {
|
||||
getFromCache = func(name string) IOOption[Player] {
|
||||
return func() Option[Player] {
|
||||
return M.MonadLookup(localStorage, name)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func Example_renderPage() {
|
||||
}
|
||||
|
||||
func Example_solution10A() {
|
||||
safeAdd := F.Curry2(func(a, b O.Option[int]) O.Option[int] {
|
||||
safeAdd := F.Curry2(func(a, b Option[int]) Option[int] {
|
||||
return F.Pipe3(
|
||||
N.Add[int],
|
||||
O.Of[func(int) func(int) int],
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
S "github.com/IBM/fp-go/v2/string"
|
||||
)
|
||||
|
||||
func findUserByID(id int) IOE.IOEither[error, Chapter08User] {
|
||||
func findUserByID(id int) IOEither[Chapter08User] {
|
||||
switch id {
|
||||
case 1:
|
||||
return IOE.Of[error](albert08)
|
||||
|
||||
@@ -45,7 +45,7 @@ var (
|
||||
validatePlayer = E.FromPredicate(P.ContraMap(Player.getName)(S.IsNonEmpty), F.Flow2(Player.getID, errors.OnSome[int]("player %d must have a name")))
|
||||
|
||||
// readfile :: String -> String -> Task Error String
|
||||
readfile = F.Curry2(func(encoding, file string) IOE.IOEither[error, string] {
|
||||
readfile = F.Curry2(func(encoding, file string) IOEither[string] {
|
||||
return IOE.Of[error](fmt.Sprintf("content of %s (%s)", file, encoding))
|
||||
})
|
||||
|
||||
@@ -80,8 +80,8 @@ func Example_solution12B() {
|
||||
|
||||
func Example_solution12C() {
|
||||
traverseO := O.Traverse[string](
|
||||
IOE.Of[error, O.Option[string]],
|
||||
IOE.Map[error, string, O.Option[string]],
|
||||
IOE.Of[error, Option[string]],
|
||||
IOE.Map[error, string, Option[string]],
|
||||
)
|
||||
|
||||
// readFirst :: String -> Task Error (Maybe String)
|
||||
|
||||
@@ -14,3 +14,17 @@
|
||||
// limitations under the License.
|
||||
|
||||
package mostlyadequate
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/v2/either"
|
||||
"github.com/IBM/fp-go/v2/ioeither"
|
||||
"github.com/IBM/fp-go/v2/iooption"
|
||||
"github.com/IBM/fp-go/v2/option"
|
||||
)
|
||||
|
||||
type (
|
||||
Either[A any] = either.Either[error, A]
|
||||
IOEither[A any] = ioeither.IOEither[error, A]
|
||||
IOOption[A any] = iooption.IOOption[A]
|
||||
Option[A any] = option.Option[A]
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestSampleConvertDocx2(t *testing.T) {
|
||||
// other than reading from a `Reader`. As a consequence it can be a pure function itself.
|
||||
// The disadvantage is that its input has to exist in memory which is probably not a good
|
||||
// idea for large inputs
|
||||
convertDocx := func(data []byte) E.Either[error, T.Tuple2[string, map[string]string]] {
|
||||
convertDocx := func(data []byte) Either[T.Tuple2[string, map[string]string]] {
|
||||
text, meta, err := sampleConvertDocx(bytes.NewReader(data))
|
||||
return E.TryCatchError(T.MakeTuple2(text, meta), err)
|
||||
}
|
||||
|
||||
22
v2/samples/tuples/types.go
Normal file
22
v2/samples/tuples/types.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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 tuples
|
||||
|
||||
import "github.com/IBM/fp-go/v2/either"
|
||||
|
||||
type (
|
||||
Either[A any] = either.Either[error, A]
|
||||
)
|
||||
Reference in New Issue
Block a user