mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: add more tests
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
5
io/eq.go
5
io/eq.go
@@ -24,3 +24,8 @@ import (
|
||||
func Eq[A any](e EQ.Eq[A]) EQ.Eq[IO[A]] {
|
||||
return G.Eq[IO[A]](e)
|
||||
}
|
||||
|
||||
// FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
|
||||
func FromStrictEquals[A comparable]() EQ.Eq[IO[A]] {
|
||||
return G.FromStrictEquals[IO[A]]()
|
||||
}
|
||||
|
26
io/functor.go
Normal file
26
io/functor.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2024 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 io
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/internal/functor"
|
||||
G "github.com/IBM/fp-go/io/generic"
|
||||
)
|
||||
|
||||
// Functor returns the monadic operations for [IO]
|
||||
func Functor[A, B any]() functor.Functor[A, B, IO[A], IO[B]] {
|
||||
return G.Functor[A, B, IO[A], IO[B]]()
|
||||
}
|
@@ -33,3 +33,8 @@ func Eq[GA ~func() A, A any](e EQ.Eq[A]) EQ.Eq[GA] {
|
||||
return eq(l, r)()
|
||||
})
|
||||
}
|
||||
|
||||
// FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
|
||||
func FromStrictEquals[GA ~func() A, A comparable]() EQ.Eq[GA] {
|
||||
return Eq[GA](EQ.FromStrictEquals[A]())
|
||||
}
|
||||
|
31
io/generic/functor.go
Normal file
31
io/generic/functor.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2024 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 generic
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/internal/functor"
|
||||
)
|
||||
|
||||
type ioFunctor[A, B any, GA ~func() A, GB ~func() B] struct{}
|
||||
|
||||
func (o *ioFunctor[A, B, GA, GB]) Map(f func(A) B) func(GA) GB {
|
||||
return Map[GA, GB, A, B](f)
|
||||
}
|
||||
|
||||
// Functor implements the functoric operations for [IO]
|
||||
func Functor[A, B any, GA ~func() A, GB ~func() B]() functor.Functor[A, B, GA, GB] {
|
||||
return &ioFunctor[A, B, GA, GB]{}
|
||||
}
|
31
io/generic/pointed.go
Normal file
31
io/generic/pointed.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2024 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 generic
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/internal/pointed"
|
||||
)
|
||||
|
||||
type ioPointed[A any, GA ~func() A] struct{}
|
||||
|
||||
func (o *ioPointed[A, GA]) Of(a A) GA {
|
||||
return Of[GA, A](a)
|
||||
}
|
||||
|
||||
// Pointed implements the pointedic operations for [IO]
|
||||
func Pointed[A any, GA ~func() A]() pointed.Pointed[A, GA] {
|
||||
return &ioPointed[A, GA]{}
|
||||
}
|
26
io/pointed.go
Normal file
26
io/pointed.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2024 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 io
|
||||
|
||||
import (
|
||||
"github.com/IBM/fp-go/internal/pointed"
|
||||
G "github.com/IBM/fp-go/io/generic"
|
||||
)
|
||||
|
||||
// Pointed returns the monadic operations for [IO]
|
||||
func Pointed[A any]() pointed.Pointed[A, IO[A]] {
|
||||
return G.Pointed[A, IO[A]]()
|
||||
}
|
@@ -16,8 +16,11 @@
|
||||
package io
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
A "github.com/IBM/fp-go/array"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
TST "github.com/IBM/fp-go/internal/testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"testing"
|
||||
@@ -45,3 +48,18 @@ func TestMapSeq(t *testing.T) {
|
||||
|
||||
assert.True(t, res())
|
||||
}
|
||||
|
||||
func TestSequenceArray(t *testing.T) {
|
||||
|
||||
s := TST.SequenceArrayTest(
|
||||
FromStrictEquals[bool](),
|
||||
Pointed[string](),
|
||||
Pointed[bool](),
|
||||
Functor[[]string, bool](),
|
||||
SequenceArray[string],
|
||||
)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Run(fmt.Sprintf("TestSequenceArray %d", i), s(i))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user