Skip to content

Commit 1b30762

Browse files
committed
Merge branch 'v2'
2 parents ef4ab4e + fc2530a commit 1b30762

File tree

125 files changed

+2075
-5628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+2075
-5628
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ If there is no such issue, consider creating one first. Discussions concerning p
1313
_Replace the space in each box with "X" to check it off._
1414

1515
- [ ] I have read and understood the CONTRIBUTING guidelines
16-
- [ ] My code is formatted (`make check`)
17-
- [ ] I have run tests (`make test`)
1816
- [ ] All commits in my PR conform to the commit hygiene section
1917
- [ ] I have added relevant tests
2018
- [ ] I have not added any dependencies

.github/workflows/test.yaml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,33 @@
11
name: test
22
on:
3-
push: { branches: [main] }
4-
pull_request: {}
3+
push: { branches: [v2] }
4+
pull_request: { branches: [v2] }
55
jobs:
66
check:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
1010
- uses: actions/setup-go@v5
1111
with:
12-
go-version: "1.22"
12+
go-version: 1.23.0-rc.1
1313
cache: false
1414
- run: make check
1515
env: { SKIP_LINT: true }
16-
- uses: golangci/golangci-lint-action@v5
17-
with: { version: "latest" }
16+
# - uses: golangci/golangci-lint-action@v4
17+
# with: { version: "latest" }
1818
- run: make cov
19+
env: { GOEXPERIMENT: rangefunc }
1920
- uses: codecov/codecov-action@v4
2021
env: { CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" }
2122
test:
2223
strategy:
2324
matrix:
2425
os: [ubuntu-latest, windows-latest, macos-latest]
25-
go-version: ["1.21", "1.22"]
2626
runs-on: ${{ matrix.os }}
2727
steps:
2828
- uses: actions/checkout@v4
2929
- uses: actions/setup-go@v5
3030
with:
31-
go-version: "${{ matrix.go-version }}"
31+
go-version: 1.23.0-rc.1
3232
cache: false
3333
- run: make test
34-
test-v2:
35-
strategy:
36-
matrix:
37-
os: [ubuntu-latest, windows-latest, macos-latest]
38-
runs-on: ${{ matrix.os }}
39-
steps:
40-
- uses: actions/checkout@v4
41-
- uses: actions/setup-go@v5
42-
with:
43-
go-version: "1.22"
44-
cache: false
45-
- run: |
46-
go work init .
47-
go work use v2
48-
make test-v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage.txt
22
.vscode/
3-
go.work
3+
go.work
4+
.envrc

Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.phony: test check lint
22

3+
GO_BINARY ?= go
4+
35
check: lint
4-
@go vet ./...
6+
@$(GO_BINARY) vet ./...
57
@gofmt -l .
68
@test -z "$$( gofmt -l . )"
79

@@ -11,13 +13,8 @@ ifndef SKIP_LINT
1113
endif
1214

1315
test:
14-
go test -race -v ./...
15-
16-
test-v2: export GOEXPERIMENT = rangefunc
17-
test-v2:
18-
go vet ./v2/...
19-
go test -v -race ./v2/...
16+
$(GO_BINARY) test -race -v ./...
2017

2118
cov: SHELL:=/bin/bash
2219
cov:
23-
go test -race -coverprofile=coverage.txt -covermode=atomic $$( go list ./... | grep -v internal )
20+
$(GO_BINARY) test -race -coverprofile=coverage.txt -covermode=atomic $$( $(GO_BINARY) list ./... | grep -v assert )

README.md

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,19 @@
22

33
[![GitHub release (with filter)](https://img.shields.io/github/v/release/BooleanCat/go-functional?sort=semver&logo=Go&color=%23007D9C)](https://github.com/BooleanCat/go-functional/releases) [![Actions Status](https://github.com/BooleanCat/go-functional/workflows/test/badge.svg)](https://github.com/BooleanCat/go-functional/actions) [![Go Reference](https://pkg.go.dev/badge/github.com/BooleanCat/go-functional.svg)](https://pkg.go.dev/github.com/BooleanCat/go-functional) [![Go Report Card](https://goreportcard.com/badge/github.com/BooleanCat/go-functional)](https://goreportcard.com/report/github.com/BooleanCat/go-functional) [![codecov](https://codecov.io/gh/BooleanCat/go-functional/branch/main/graph/badge.svg?token=N2E43RSR14)](https://codecov.io/gh/BooleanCat/go-functional)
44

5-
A general purpose library offering functional helpers for Golang.
5+
A library of iterators for use with `iter.Seq`.
66

77
```go
8-
// Find the first 5 even numbers
9-
evens := iter.Count().Filter(filters.IsEven).Take(5).Collect()
10-
reflect.DeepEqual(evens, []int{0, 2, 4, 6, 8})
11-
```
12-
13-
_[Read the docs.](https://pkg.go.dev/github.com/BooleanCat/go-functional)_
14-
15-
## Core concepts
16-
17-
This library introduces two core concepts, the `Iterator` and the `Option`.
18-
Using these two concepts this library derives many pre-defined iterators for
19-
use.
20-
21-
### The `Option`
22-
23-
The `Option` is simply a type that represents the presence or absence of a
24-
value. Options behave somewhat like enumerations with two variants:
25-
`Some(value)` and `None`.
26-
27-
### The `Iterator`
28-
29-
```go
30-
type Iterator[T any] interface {
31-
Next() option.Option[T]
32-
}
33-
```
8+
// The first 5 natural numbers
9+
numbers := slices.Collect(
10+
it.Take(it.Count(), 5),
11+
)
3412

35-
The `Iterator` is an interface that defines the behaviour of some type that
36-
"yields" values. Each call to `Next()` on an `Iterator` will yield another
37-
value as defined by that specific `Iterator`. For example, the iterator
38-
`iter.Count()` yields 0, 1, 2, 3, etc. and onwards to infinity (or the integer
39-
limit!).
13+
// All even numbers
14+
evens := it.Filter(it.Count(), filter.IsEven)
4015

41-
Iterators will yield `Some(value)` for as long as they have values to yield.
42-
Iterators that have exhausted all their values will then always yield `None`.
43-
44-
This library defines many iterators and a few are demonstrated below. For the
45-
entire set simply visit the
46-
[package documentation](https://pkg.go.dev/github.com/BooleanCat/go-functional/iter).
47-
48-
### Iterator showcase
49-
50-
Here are a few trivial example of what's possible using the iterators in this
51-
library.
52-
53-
```go
54-
// All odd natural numbers (1, 3, 5, 7...)
55-
odds := iter.Count().Drop(1).Filter(filters.IsOdd).Collect()
16+
// String representations of integers
17+
numbers := it.Map(it.Count(), strconv.Itoa)
5618
```
5719

58-
```go
59-
// All lines from a file
60-
lines := iter.LinesString(file).CollectResults().Unwrap()
61-
```
62-
63-
```go
64-
// String representations of numbers
65-
numbers := iter.Map(iter.Count(), strconv.Itoa)
66-
```
20+
_[Read the docs](https://pkg.go.dev/github.com/BooleanCat/go-functional)_ to see the full iterator library.

constraints/constraints.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/BooleanCat/go-functional
1+
module github.com/BooleanCat/go-functional/v2
22

3-
go 1.20
3+
go 1.23

internal/assert/assert.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,70 @@ package assert
22

33
import "testing"
44

5-
func Equal[T comparable](t *testing.T, a, b T) {
5+
func True(t *testing.T, value bool) {
66
t.Helper()
77

8-
if a != b {
9-
t.Errorf("expected `%v` to equal `%v`", a, b)
8+
if !value {
9+
t.Error("expected true")
1010
}
1111
}
1212

13-
func True(t *testing.T, b bool) {
13+
func False(t *testing.T, value bool) {
1414
t.Helper()
1515

16-
if !b {
17-
t.Error("expected `false` to be `true`")
16+
if value {
17+
t.Error("expected false")
1818
}
1919
}
2020

21-
func False(t *testing.T, b bool) {
21+
func Equal[T comparable](t *testing.T, a, b T) {
2222
t.Helper()
2323

24-
if b {
25-
t.Error("expected `true` to be `false`")
24+
if a != b {
25+
t.Errorf("expected `%v` to equal `%v`", a, b)
2626
}
2727
}
2828

29-
func Nil(t *testing.T, v interface{}) {
29+
func SliceEqual[T comparable](t *testing.T, a, b []T) {
3030
t.Helper()
3131

32-
if v != nil {
33-
t.Errorf("expected `%v` to equal `nil`", v)
32+
if len(a) != len(b) {
33+
t.Errorf("expected `%v` to equal `%v` but lengths differ", a, b)
34+
return
3435
}
35-
}
36-
37-
func NotNil(t *testing.T, v interface{}) {
38-
t.Helper()
3936

40-
if v == nil {
41-
t.Error("expected `nil` not to equal `nil`")
37+
for i, v := range a {
38+
if v != b[i] {
39+
t.Errorf("expected `%v` to equal `%v`", a, b)
40+
}
4241
}
4342
}
4443

45-
func SliceEqual[T comparable](t *testing.T, a, b []T) {
44+
func EqualElements[T comparable](t *testing.T, a, b []T) {
4645
t.Helper()
4746

4847
if len(a) != len(b) {
4948
t.Errorf("expected `%v` to equal `%v` but lengths differ", a, b)
5049
return
5150
}
5251

53-
for i, v := range a {
54-
if v != b[i] {
55-
t.Errorf("expected `%v` to equal `%v`", a, b)
52+
for _, v := range a {
53+
found := false
54+
55+
for _, w := range b {
56+
if v == w {
57+
found = true
58+
break
59+
}
60+
}
61+
62+
if !found {
63+
t.Errorf("expected `%v` to contain the same elements as `%v`", a, b)
5664
}
5765
}
5866
}
5967

60-
func Empty[S any, T []S | ~string](t *testing.T, items T) {
68+
func Empty[E any, Slice ~[]E | ~string](t *testing.T, items Slice) {
6169
t.Helper()
6270

6371
if len(items) != 0 {

internal/fakes/iterator.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)