Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- main
- dev
- "dev**"
- "go**"
- "releases/**"
- "feature/**"
- "bugfix/**"
Expand All @@ -27,8 +28,14 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3
- name: run tests
uses: docker://golang:1.24-bullseye
- name: Set up Go
uses: actions/setup-go@v5
with:
args: make build lint bench cover-console-out

go-version: '1.27'
cache: true
- name: setup Task
uses: go-task/setup-task@v2
with:
version: 3.x
- name: run tests
run: task build lint bench cover-console-out
23 changes: 7 additions & 16 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ linters:
- godot
- depguard
- godox
- exhaustruct
- exhaustruct_v5
exclusions:
rules:
- path: op/api\.go
Expand All @@ -39,7 +41,7 @@ linters:
- testifylint
- gochecknoglobals
- forbidigo
- exhaustruct
- exhaustruct_v5
- goconst
- gocritic
- revive
Expand All @@ -55,18 +57,7 @@ linters:
- intrange
- modernize
- gocritic
settings:
revive:
rules:
- name: var-naming
disabled: true
severity: warning
gocritic:
settings:
ifElseChain:
minThreshold: 4
exhaustruct:
allow-empty: true
testifylint:
disable:
- require-error
- goconst
- testifylint
- revive

8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
"go.formatFlags": [
"fmt",
"--stdin"
]
],
"yaml.schemas": {
"file:///c%3A/Users/mfour/.vscode-oss/extensions/continue.continue-2.0.0-win32-x64/config-yaml-schema.json": [
".continue/**/*.yaml"
],
"file:///c:/Users/mfour/.vscode-oss/extensions/continue.continue-2.0.0-win32-x64/config-yaml-schema.json": "file:///c%3A/Users/mfour/.continue/config.yaml"
}
}
69 changes: 0 additions & 69 deletions Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var namesByRole = group.ByMultipleKeys(users, func(u User) []string {

## Installation

``` console
```
go get -u github.com/m4gshm/gollections
```

Expand Down Expand Up @@ -818,7 +818,7 @@ Provides implelentations of [Vector](./collection/iface.go#L25),
[Set](./collection/iface.go#L35) and [Map](./collection/iface.go#L41).

Mutables support content appending, updating and deleting (the ordered
map implementation is not supported delete operations).
map implementation is not supported delete operations).\
Immutables are read-only datasets.

Detailed description of implementations [below](#mutable-collections).
Expand All @@ -842,7 +842,7 @@ bob, _ := slice.First(users, where.Eq(User.Name, "Bob"))
### Expressions: [use.If](./expr/use/api.go), [get.If](./expr/get/api.go), [first.Of](#firstof), [last.Of](#lastof)

Aimed to evaluate a value using conditions. May cause to make code
shorter by not in all cases.
shorter by not in all cases.\
As example:

``` go
Expand Down
74 changes: 74 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '3'

vars:
GO_FLAGS: "-gcflags -m"

tasks:
default:
deps: [clean, build, test, readme, lint, bench]

clean:
cmds:
- echo "#Cleaning..."
- go clean -cache
- go clean -testcache

build:
cmds:
- echo "#Building..."
- go env -w GOEXPERIMENT=newinliner
- go fmt ./...
- go vet ./...
- go build ./...

builda:
cmds:
- echo "#Building..."
- go clean -cache
- go build -gcflags $(GO_FLAGS) ./...

test:
cmds:
- echo "#Running tests..."
- go test ./...

cover:
cmds:
- echo "#Running cover tests..."
- go test -coverprofile=coverage.out -coverpkg=github.com/m4gshm/gollections/... ./...
- go tool cover -html=coverage.out

cover-console-out:
cmds:
- echo "#Running cover tests..."
- go test -coverprofile=coverage.out -coverpkg=github.com/m4gshm/gollections/... ./...
- go tool cover -func=coverage.out

bench:
cmds:
- echo "#Running benchmarks..."
- go env -w GOEXPERIMENT=newinliner
- go test -benchtime 1s -bench . -benchmem ./...

update:
cmds:
- echo "#Update tools..."
- go install github.com/go-delve/delve/cmd/dlv@latest
- go install golang.org/x/tools/gopls@latest

lint:
cmds:
- echo "#Lints..."
# - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
- golangci-lint run

readme:
cmds:
- echo "#README.md..."
- asciidoctor -b docbook internal/docs/readme.adoc
- pandoc -f docbook -t gfm internal/docs/readme.xml -o README.md

pkgsite:
cmds:
- go install golang.org/x/pkgsite/cmd/pkgsite@latest
- pkgsite
6 changes: 0 additions & 6 deletions c/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ type Filterable[T any, Seq ~func(yield func(T) bool), SeqE ~func(yield func(T, e
Filt(predicate func(T) (bool, error)) SeqE
}

// Convertable provides converaton of collection elements functionality
type Convertable[T any, Seq ~func(yield func(T) bool), SeqE ~func(yield func(T, error) bool)] interface {
Convert(converter func(T) T) Seq
Conv(converter func(T) (T, error)) SeqE
}

// SliceFactory collects the elements of the collection into a slice
type SliceFactory[T any] interface {
Slice() []T
Expand Down
2 changes: 0 additions & 2 deletions collection/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
type Collection[T any] interface {
c.Collection[T]
c.Filterable[T, seq.Seq[T], seq.SeqE[T]]
c.Convertable[T, seq.Seq[T], seq.SeqE[T]]

Len() int
IsEmpty() bool
Expand All @@ -33,7 +32,6 @@ type Set[T comparable] interface {
type Map[K comparable, V any] interface {
kv.Collection[K, V, map[K]V]
kv.Filterable[K, V, seq.Seq2[K, V], seq.SeqE[c.KV[K, V]]]
kv.Convertable[K, V, seq.Seq2[K, V], seq.SeqE[c.KV[K, V]]]
c.Checkable[K]
c.Access[K, V]
c.KVRange[K, V]
Expand Down
4 changes: 2 additions & 2 deletions collection/immutable/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func (m MapKeys[K, V]) Filt(filter func(K) (bool, error)) seq.SeqE[K] {
}

// Convert returns a seq that applies the 'converter' function to the collection elements
func (m MapKeys[K, V]) Convert(converter func(K) K) seq.Seq[K] {
func (m MapKeys[K, V]) Convert[O any](converter func(K) O) seq.Seq[O] {
return collection.Convert(m, converter)
}

// Conv returns an errorable seq that applies the 'converter' function to the collection elements
func (m MapKeys[K, V]) Conv(converter func(K) (K, error)) seq.SeqE[K] {
func (m MapKeys[K, V]) Conv[O any](converter func(K) (O, error)) seq.SeqE[O] {
return collection.Conv(m, converter)
}

Expand Down
12 changes: 6 additions & 6 deletions collection/immutable/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ func (m Map[K, V]) FiltKey(filter func(K) (bool, error)) seq.SeqE[c.KV[K, V]] {
}

// ConvertKey returns a seq that applies the 'converter' function to keys of the map
func (m Map[K, V]) ConvertKey(converter func(K) K) seq.Seq2[K, V] {
func (m Map[K, V]) ConvertKey[KO comparable](converter func(K) KO) seq.Seq2[KO, V] {
return seq2.Convert(m.All, convert.Key[V](converter))
}

// ConvKey returns an errorable seq that applies the 'converter' function to keys of the map
func (m Map[K, V]) ConvKey(converter func(K) (K, error)) seq.SeqE[c.KV[K, V]] {
func (m Map[K, V]) ConvKey[KO comparable](converter func(K) (KO, error)) seq.SeqE[c.KV[KO, V]] {
return seq2.Conv(m.All, converte.Key[V](converter))
}

Expand All @@ -145,12 +145,12 @@ func (m Map[K, V]) FiltValue(filter func(V) (bool, error)) seq.SeqE[c.KV[K, V]]
}

// ConvertValue returns a seq that applies the 'converter' function to values of the map
func (m Map[K, V]) ConvertValue(converter func(V) V) seq.Seq2[K, V] {
func (m Map[K, V]) ConvertValue[VO any](converter func(V) VO) seq.Seq2[K, VO] {
return seq2.Convert(m.All, convert.Value[K](converter))
}

// ConvValue returns an errorable seq that applies the 'converter' function to values of the map
func (m Map[K, V]) ConvValue(converter func(V) (V, error)) seq.SeqE[c.KV[K, V]] {
func (m Map[K, V]) ConvValue[VO any](converter func(V) (VO, error)) seq.SeqE[c.KV[K, VO]] {
return seq2.Conv(m.All, converte.Value[K](converter))
}

Expand All @@ -165,12 +165,12 @@ func (m Map[K, V]) Filt(filter func(K, V) (bool, error)) seq.SeqE[c.KV[K, V]] {
}

// Convert returns a seq that applies the 'converter' function to the collection elements
func (m Map[K, V]) Convert(converter func(K, V) (K, V)) seq.Seq2[K, V] {
func (m Map[K, V]) Convert[KO comparable, VO any](converter func(K, V) (KO, VO)) seq.Seq2[KO, VO] {
return seq2.Convert(m.All, converter)
}

// Conv returns an errorable seq that applies the 'converter' function to the collection elements
func (m Map[K, V]) Conv(converter func(K, V) (K, V, error)) seq.SeqE[c.KV[K, V]] {
func (m Map[K, V]) Conv[KO comparable, VO any](converter func(K, V) (KO, VO, error)) seq.SeqE[c.KV[KO, VO]] {
return seq2.Conv(m.All, converter)
}

Expand Down
14 changes: 7 additions & 7 deletions collection/immutable/map_/test/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ func Test_Map_Zero(t *testing.T) {
m.FilterValue(nil)

m.Values().ForEach(nil)
m.ConvertValue(nil).TrackEach(nil)
m.ConvertValue(nil).Filter(nil).FilterKey(nil)
m.ConvertValue(nil).Filter(nil).FilterValue(nil)
m.ConvertValue[string](nil).TrackEach(nil)
m.ConvertValue[string](nil).Filter(nil).FilterKey(nil)
m.ConvertValue[string](nil).Filter(nil).FilterValue(nil)

m.Keys().ForEach(nil)
m.ConvertKey(nil).TrackEach(nil)
m.ConvertKey(nil).Filter(nil).FilterKey(nil)
m.ConvertKey(nil).Filter(nil).FilterValue(nil)
m.Convert(nil)
m.ConvertKey[string](nil).TrackEach(nil)
m.ConvertKey[string](nil).Filter(nil).FilterKey(nil)
m.ConvertKey[string](nil).Filter(nil).FilterValue(nil)
m.Convert[any, string](nil)

m.Sort(nil).TrackEach(nil)

Expand Down
4 changes: 2 additions & 2 deletions collection/immutable/ordered/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func (m MapKeys[K]) Filt(filter func(K) (bool, error)) seq.SeqE[K] {
}

// Convert returns a seq that applies the 'converter' function to the collection elements
func (m MapKeys[K]) Convert(converter func(K) K) seq.Seq[K] {
func (m MapKeys[K]) Convert[O any](converter func(K) O) seq.Seq[O] {
return collection.Convert(m, converter)
}

// Conv returns an errorable seq that applies the 'converter' function to the collection elements
func (m MapKeys[K]) Conv(converter func(K) (K, error)) seq.SeqE[K] {
func (m MapKeys[K]) Conv[O any](converter func(K) (O, error)) seq.SeqE[O] {
return collection.Conv(m, converter)
}

Expand Down
Loading
Loading