From 74763bdadc7493216432324a7e0edb326ae4dfcd Mon Sep 17 00:00:00 2001 From: Francis Zhou Date: Mon, 11 Mar 2024 23:18:30 +0800 Subject: [PATCH] correct the generic type for FromIO (#104) Signed-off-by: francis --- either/either.go | 2 +- either/either_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/either/either.go b/either/either.go index 006b301..992ef6d 100644 --- a/either/either.go +++ b/either/either.go @@ -33,7 +33,7 @@ func Of[E, A any](value A) Either[E, A] { return F.Pipe1(value, Right[E, A]) } -func FromIO[E, IO ~func() A, A any](f IO) Either[E, A] { +func FromIO[E any, IO ~func() A, A any](f IO) Either[E, A] { return F.Pipe1(f(), Right[E, A]) } diff --git a/either/either_test.go b/either/either_test.go index a413598..7f50a21 100644 --- a/either/either_test.go +++ b/either/either_test.go @@ -71,7 +71,6 @@ func TestReduce(t *testing.T) { assert.Equal(t, "foo", F.Pipe1(Left[string, string]("bar"), Reduce[string](s.Concat, "foo"))) } - func TestAp(t *testing.T) { f := S.Size @@ -120,3 +119,10 @@ func TestStringer(t *testing.T) { var s fmt.Stringer = e assert.Equal(t, exp, s.String()) } + +func TestFromIO(t *testing.T) { + f := func() string { return "abc" } + e := FromIO[error](f) + + assert.Equal(t, Right[error]("abc"), e) +}