Skip to content

Commit 89ea2a0

Browse files
committed
feat: add missing methods, add Rakefile
1 parent 36e5c29 commit 89ea2a0

File tree

11 files changed

+1021
-175
lines changed

11 files changed

+1021
-175
lines changed

.github/workflows/matrix-test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
name: Golang ${{ matrix.go }}
1919
strategy:
20+
fail-fast: false
2021
matrix:
2122
go:
2223
- "1.25"
@@ -28,7 +29,9 @@ jobs:
2829
uses: actions/setup-go@v5
2930
with:
3031
go-version: ${{ matrix.go }}
32+
# - name: Install Rake
33+
# run: gem install rake
3134
- name: Test option
32-
run: cd option && go test -v
35+
run: rake test_option
3336
- name: Test result
34-
run: cd result && go test -v
37+
run: rake test_result

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/**/*.rs

README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,54 @@
1-
# type
1+
# types
22

3-
Bring the Rust [Result Option] type to Golang
3+
Bring the Rust [Result Option] types to Golang
44

55
## Installation
66

7-
`go get github.com/initdc/type`
7+
`go get github.com/initdc/types`
88

99
## Usage
1010

1111
```go
12+
package e2e_test
13+
1214
import (
13-
. "github.com/initdc/type/option"
14-
. "github.com/initdc/type/result"
15+
"fmt"
16+
. "github.com/initdc/types/option"
17+
types "github.com/initdc/types/result"
18+
"testing"
1519
)
1620

17-
// Option
18-
s := Some(1)
21+
func TestE2E(t *testing.T) {
22+
// Option
23+
s1 := Some(1)
24+
25+
var s2 Option[int]
26+
s2.None()
27+
28+
n1 := None[int]()
1929

20-
var s Option[int]
21-
s.None()
2230

23-
n := None[int]()
31+
// Result
32+
var r1 types.Result[int, string]
33+
r1.Ok(1)
2434

25-
// Result
26-
var r Result[int, string]
27-
r.Ok(1)
35+
var e1 types.Result[int, string]
36+
e1.Err("error")
2837

29-
var e Result[int, string]
30-
e.Err("error")
38+
r2 := types.Ok[int, string](1)
39+
e2 := types.Err[int, string]("error")
3140

41+
fmt.Printf("%#v\n", s1)
42+
fmt.Printf("%#v\n", s2)
43+
fmt.Printf("%#v\n", n1)
3244

33-
r := Ok[int, string](1)
34-
e := Err[int, string]("error")
45+
fmt.Printf("%#v\n", r1)
46+
fmt.Printf("%#v\n", e1)
47+
fmt.Printf("%#v\n", r2)
48+
fmt.Printf("%#v\n", e2)
49+
}
3550
```
3651

3752
## Contributing
3853

39-
Bug reports and pull requests are welcome on GitHub at https://github.com/initdc/type.
54+
Bug reports and pull requests are welcome on GitHub at https://github.com/initdc/types.

Rakefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
task default: %w[fmt vet test]
2+
3+
task :fmt do
4+
sh "go fmt ./..."
5+
end
6+
7+
task :vet do
8+
sh "go vet ./..."
9+
end
10+
11+
task :test do
12+
sh "go test -cover -v ./..."
13+
end
14+
15+
task :test_result do
16+
sh "go test -cover -v ./result"
17+
end
18+
19+
task :test_option do
20+
sh "go test -cover -v ./option"
21+
end

e2e_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package e2e_test
2+
3+
import (
4+
"fmt"
5+
. "github.com/initdc/types/option"
6+
types "github.com/initdc/types/result"
7+
"testing"
8+
)
9+
10+
func TestE2E(t *testing.T) {
11+
// Option
12+
s1 := Some(1)
13+
14+
var s2 Option[int]
15+
s2.None()
16+
17+
n1 := None[int]()
18+
19+
20+
// Result
21+
var r1 types.Result[int, string]
22+
r1.Ok(1)
23+
24+
var e1 types.Result[int, string]
25+
e1.Err("error")
26+
27+
r2 := types.Ok[int, string](1)
28+
e2 := types.Err[int, string]("error")
29+
30+
fmt.Printf("%#v\n", s1)
31+
fmt.Printf("%#v\n", s2)
32+
fmt.Printf("%#v\n", n1)
33+
34+
fmt.Printf("%#v\n", r1)
35+
fmt.Printf("%#v\n", e1)
36+
fmt.Printf("%#v\n", r2)
37+
fmt.Printf("%#v\n", e2)
38+
}

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
module github.com/initdc/type
1+
module github.com/initdc/types
22

33
go 1.18
4+
5+
require github.com/stretchr/testify v1.11.1
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
6+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)