Compare commits

..

36 Commits

Author SHA1 Message Date
semantic-release-bot
ccd10395e9 release(rc): v0.1.1-rc.11
All checks were successful
ci/woodpecker/push/release Pipeline was successful
## [0.1.1-rc.11](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.10...v0.1.1-rc.11) (2024-05-27)

### Refactoring

* **comments:** beautify comments ([b3d5fbf](b3d5fbf332))
* **tests:** move `person` type to test function ([c0fb09e](c0fb09e573))

### Continuous Integrations

* **test:** remove `group` directive ([78b8b10](78b8b10998))

### Build system and dependencies

* **deps:** update project dependencies ([210cb07](210cb07c17))
2024-05-27 23:36:50 +00:00
134fdfdfd7
docs(package): add simple README.md and package descriptions
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-05-28 01:35:57 +02:00
210cb07c17
build(deps): update project dependencies 2024-05-28 01:31:49 +02:00
c0fb09e573
refactor(tests): move person type to test function 2024-05-28 01:30:00 +02:00
b3d5fbf332
refactor(comments): beautify comments 2024-05-28 01:28:25 +02:00
78b8b10998
ci(test): remove group directive 2024-05-28 01:11:23 +02:00
semantic-release-bot
d0174a8432 release(rc): v0.1.1-rc.10
## [0.1.1-rc.10](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.9...v0.1.1-rc.10) (2024-05-21)

###  Tests

* **fixtures:** embed test fixtures ([563848c](563848c2fb))

### Continuous Integrations

* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([739f469](739f469fbd))

### Build system and dependencies

* **deps:** update all non-major dependencies ([45caf52](45caf527e5))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([c735657](c735657b03))
2024-05-21 21:07:58 +00:00
739f469fbd
ci(deps): pin conventional-changelog-conventionalcommits to version 7.x
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-05-21 23:07:28 +02:00
563848c2fb
test(fixtures): embed test fixtures 2024-05-21 23:05:21 +02:00
45caf527e5 build(deps): update all non-major dependencies
Some checks failed
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline failed
ci/woodpecker/push/test Pipeline was successful
2024-05-15 13:15:26 +02:00
c735657b03 build(deps): update dependency conventional-changelog-conventionalcommits to v8
Some checks failed
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline failed
ci/woodpecker/push/test Pipeline was successful
2024-05-04 00:01:45 +00:00
semantic-release-bot
ba0dc5675e release(rc): v0.1.1-rc.9
## [0.1.1-rc.9](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.8...v0.1.1-rc.9) (2024-04-12)

### Build system and dependencies

* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([7de8723](7de8723b78))
2024-04-12 12:42:51 +00:00
7de8723b78 build(deps): update dependency @semantic-release/release-notes-generator to v13
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-04-12 12:41:03 +00:00
semantic-release-bot
f9044e2bbe release(rc): v0.1.1-rc.8
## [0.1.1-rc.8](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.7...v0.1.1-rc.8) (2024-04-12)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.8 ([489048c](489048c232))
2024-04-12 12:40:23 +00:00
489048c232 build(deps): update dependency semantic-release to v23.0.8
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-04-10 00:01:48 +00:00
semantic-release-bot
60429dbf66 release(rc): v0.1.1-rc.7
## [0.1.1-rc.7](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.6...v0.1.1-rc.7) (2024-03-23)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.5 ([9994912](9994912f87))
2024-03-23 23:22:39 +00:00
9994912f87 build(deps): update dependency semantic-release to v23.0.5
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-23 23:20:02 +00:00
semantic-release-bot
50ad1dc949 release(rc): v0.1.1-rc.6
## [0.1.1-rc.6](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.5...v0.1.1-rc.6) (2024-03-23)

### Build system and dependencies

* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([753965d](753965d7d7))
2024-03-23 23:19:17 +00:00
753965d7d7 build(deps): update dependency @semantic-release/commit-analyzer to v12
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-19 00:01:54 +00:00
semantic-release-bot
2ecfca20c4 release(rc): v0.1.1-rc.5
## [0.1.1-rc.5](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.4...v0.1.1-rc.5) (2024-03-17)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.4 ([cb21cd1](cb21cd13f5))
2024-03-17 11:39:51 +00:00
cb21cd13f5 build(deps): update dependency semantic-release to v23.0.4
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-17 11:38:40 +00:00
semantic-release-bot
79c281d80d release(rc): v0.1.1-rc.4
## [0.1.1-rc.4](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.3...v0.1.1-rc.4) (2024-03-17)

### Build system and dependencies

* **deps:** update dependency @semantic-release/npm to v12 ([8ab3f7a](8ab3f7a261))
2024-03-17 11:35:48 +00:00
8ab3f7a261 build(deps): update dependency @semantic-release/npm to v12
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-17 11:34:01 +00:00
semantic-release-bot
d7b10673d2 release(rc): v0.1.1-rc.3
## [0.1.1-rc.3](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.2...v0.1.1-rc.3) (2024-03-16)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.3 ([6a678d4](6a678d45ca))
2024-03-16 00:08:03 +00:00
6a678d45ca build(deps): update dependency semantic-release to v23.0.3
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-16 00:03:02 +00:00
semantic-release-bot
a766939d10 release(rc): v0.1.1-rc.2
## [0.1.1-rc.2](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.1...v0.1.1-rc.2) (2024-03-02)

### Continuous Integrations

* **renovate:** add Renovate bot configuration ([d831943](d831943b12))

### Build system and dependencies

* **deps:** update all non-major dependencies ([4535c6a](4535c6a712))
* **deps:** update dependency @semantic-release/npm to v11.0.3 ([21a7e54](21a7e54167))
* **deps:** update dependency semantic-release to v23 ([cc414e0](cc414e0bd8))
2024-03-02 15:18:16 +00:00
8c22323688 Merge pull request 'build(deps): update dependency @semantic-release/npm to v11.0.3' (#5) from renovate-all-minor-patch into devel
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
Reviewed-on: #5
2024-03-02 16:17:19 +01:00
21a7e54167 build(deps): update dependency @semantic-release/npm to v11.0.3
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
2024-03-02 00:01:50 +00:00
801f673bd3 Merge pull request 'build(deps): update all non-major dependencies' (#2) from renovate-all-minor-patch into devel
Reviewed-on: #2
2024-02-29 00:54:25 +01:00
4535c6a712 build(deps): update all non-major dependencies 2024-02-28 23:53:32 +00:00
067caf6097 Merge pull request 'build(deps): update dependency semantic-release to v23' (#3) from renovate-major-all-major into devel
Reviewed-on: #3
2024-02-29 00:52:24 +01:00
cc414e0bd8 build(deps): update dependency semantic-release to v23 2024-02-28 23:45:48 +00:00
d831943b12
ci(renovate): add Renovate bot configuration 2024-02-29 00:18:52 +01:00
semantic-release-bot
177b17985c release(rc): v0.1.1-rc.1
## [0.1.1-rc.1](https://git.ext.icikowski.pl/go/collections/compare/v0.1.0...v0.1.1-rc.1) (2023-11-04)

### Continuous Integrations

* **init:** add initial CI configuration ([adbb987](adbb987cbd))
2023-11-04 20:18:00 +00:00
4350ce9f2b Merge pull request 'Add Woodpecker CI support' (#1) from ci into devel
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
Reviewed-on: #1
2023-11-04 21:17:35 +01:00
adbb987cbd
ci(init): add initial CI configuration
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
2023-11-04 20:37:00 +01:00
21 changed files with 8628 additions and 62 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.vscode/*
node_modules/*

152
.releaserc.json Normal file
View File

@ -0,0 +1,152 @@
{
"branches": [
{
"name": "main",
"channel": "stable",
"prerelease": false
},
{
"name": "devel",
"channel": "rc",
"prerelease": "rc"
}
],
"plugins": [
[
"@semantic-release/commit-analyzer", {
"preset": "conventionalcommits",
"releaseRules": [
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": false
},
{
"type": "style",
"release": false
},
{
"type": "refactor",
"release": "patch"
},
{
"type": "perf",
"release": "minor"
},
{
"type": "test",
"release": "patch"
},
{
"type": "build",
"release": "patch"
},
{
"type": "ci",
"release": "patch"
},
{
"type": "revert",
"release": "patch"
},
{
"type": "release",
"release": false
}
],
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
}
}
],
[
"@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "docs",
"hidden": true
},
{
"type": "refactor",
"section": "Refactoring",
"hidden": false
},
{
"type": "perf",
"section": "Performance Improvements",
"hidden": false
},
{
"type": "test",
"section": " Tests",
"hidden": false
},
{
"type": "ci",
"section": "Continuous Integrations",
"hidden": false
},
{
"type": "chore",
"hidden": true
},
{
"type": "revert",
"section": "Reverts",
"hidden": false
},
{
"type": "release",
"hidden": true
},
{
"type": "build",
"section": "Build system and dependencies",
"hidden": false
}
]
}
}
],
[
"@semantic-release/changelog", {
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/npm", {
"npmPublish": false
}
],
["@saithodev/semantic-release-gitea", {
"giteaUrl": "https://git.ext.icikowski.pl"
}],
[
"@semantic-release/git", {
"assets": ["CHANGELOG.md","package.json", "package-lock.json"],
"message": "release(${nextRelease.channel}): v${nextRelease.version}\n\n${nextRelease.notes}"
}
]
],
"preset": "conventionalcommits"
}

38
.renovaterc.json Normal file
View File

@ -0,0 +1,38 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>renovate/renovate"
],
"packageRules": [
{
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch",
"matchPackagePatterns": [
"*"
],
"matchUpdateTypes": [
"minor",
"patch",
"pin",
"digest"
],
"automerge": false
},
{
"groupName": "all major dependencies",
"groupSlug": "all-major",
"matchPackagePatterns": [
"*"
],
"matchUpdateTypes": [
"major"
],
"automerge": false
}
],
"ignoreDeps": [],
"postUpdateOptions": [
"gomodTidy",
"gomodUpdateImportPaths"
]
}

13
.woodpecker/.release.yml Normal file
View File

@ -0,0 +1,13 @@
when:
- event: push
evaluate: '(CI_COMMIT_BRANCH == "devel" && not (CI_COMMIT_MESSAGE startsWith "release")) || (CI_COMMIT_BRANCH == "main" && not (CI_COMMIT_MESSAGE startsWith "release(stable)"))'
steps:
semantic-release:
image: node:latest
secrets:
- gitea_token
- git_credentials
commands:
- npm i
- npm run release

10
.woodpecker/.test.yml Normal file
View File

@ -0,0 +1,10 @@
when:
- event: [push, pull_request]
branch: devel
evaluate: 'not (CI_COMMIT_MESSAGE startsWith "release")'
steps:
test:
image: golang:1.22-alpine
commands:
- go test -v ./...

105
CHANGELOG.md Normal file
View File

@ -0,0 +1,105 @@
## [0.1.1-rc.11](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.10...v0.1.1-rc.11) (2024-05-27)
### Refactoring
* **comments:** beautify comments ([b3d5fbf](https://git.ext.icikowski.pl/go/collections/commit/b3d5fbf332089a5f50ec09af06bfcde627984955))
* **tests:** move `person` type to test function ([c0fb09e](https://git.ext.icikowski.pl/go/collections/commit/c0fb09e573c7cdb9a630d15e21e2eb61718a1060))
### Continuous Integrations
* **test:** remove `group` directive ([78b8b10](https://git.ext.icikowski.pl/go/collections/commit/78b8b109987da0d1f769e06b7a0794077a75865d))
### Build system and dependencies
* **deps:** update project dependencies ([210cb07](https://git.ext.icikowski.pl/go/collections/commit/210cb07c178c727a618018f61c80b9a6aee54701))
## [0.1.1-rc.10](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.9...v0.1.1-rc.10) (2024-05-21)
### Tests
* **fixtures:** embed test fixtures ([563848c](https://git.ext.icikowski.pl/go/collections/commit/563848c2fb94637046a3c87e7717ec960f546154))
### Continuous Integrations
* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([739f469](https://git.ext.icikowski.pl/go/collections/commit/739f469fbd891866529b9a8acf21a42b6a3d1c7e))
### Build system and dependencies
* **deps:** update all non-major dependencies ([45caf52](https://git.ext.icikowski.pl/go/collections/commit/45caf527e51ea272f2351d2f35d12af4030c0678))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([c735657](https://git.ext.icikowski.pl/go/collections/commit/c735657b0364fd68656ee89756193fe52a5030ad))
## [0.1.1-rc.9](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.8...v0.1.1-rc.9) (2024-04-12)
### Build system and dependencies
* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([7de8723](https://git.ext.icikowski.pl/go/collections/commit/7de8723b78db006cbad135139526941cb621f912))
## [0.1.1-rc.8](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.7...v0.1.1-rc.8) (2024-04-12)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.8 ([489048c](https://git.ext.icikowski.pl/go/collections/commit/489048c23261cc5c61d73f6d62dbc112b41c798f))
## [0.1.1-rc.7](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.6...v0.1.1-rc.7) (2024-03-23)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.5 ([9994912](https://git.ext.icikowski.pl/go/collections/commit/9994912f870ed00b8d97bae72af10e5ad532ace0))
## [0.1.1-rc.6](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.5...v0.1.1-rc.6) (2024-03-23)
### Build system and dependencies
* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([753965d](https://git.ext.icikowski.pl/go/collections/commit/753965d7d7fdc9c0a017fa772899c51f4fe0e0f4))
## [0.1.1-rc.5](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.4...v0.1.1-rc.5) (2024-03-17)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.4 ([cb21cd1](https://git.ext.icikowski.pl/go/collections/commit/cb21cd13f59139644fcdeae127e89a9bf3e6b624))
## [0.1.1-rc.4](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.3...v0.1.1-rc.4) (2024-03-17)
### Build system and dependencies
* **deps:** update dependency @semantic-release/npm to v12 ([8ab3f7a](https://git.ext.icikowski.pl/go/collections/commit/8ab3f7a261d6781598d07a45bcaa245379fccb47))
## [0.1.1-rc.3](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.2...v0.1.1-rc.3) (2024-03-16)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.3 ([6a678d4](https://git.ext.icikowski.pl/go/collections/commit/6a678d45cabe8d20708f8b46e3087402a6d53123))
## [0.1.1-rc.2](https://git.ext.icikowski.pl/go/collections/compare/v0.1.1-rc.1...v0.1.1-rc.2) (2024-03-02)
### Continuous Integrations
* **renovate:** add Renovate bot configuration ([d831943](https://git.ext.icikowski.pl/go/collections/commit/d831943b121bb91ec53c2bc8a269eade81b76047))
### Build system and dependencies
* **deps:** update all non-major dependencies ([4535c6a](https://git.ext.icikowski.pl/go/collections/commit/4535c6a712833eb0d931f67040233ab690561fc3))
* **deps:** update dependency @semantic-release/npm to v11.0.3 ([21a7e54](https://git.ext.icikowski.pl/go/collections/commit/21a7e541676f7afe799a6d86d1bb0709e070a6ab))
* **deps:** update dependency semantic-release to v23 ([cc414e0](https://git.ext.icikowski.pl/go/collections/commit/cc414e0bd87979ca39a0fb799c76802a887cd82f))
## [0.1.1-rc.1](https://git.ext.icikowski.pl/go/collections/compare/v0.1.0...v0.1.1-rc.1) (2023-11-04)
### Continuous Integrations
* **init:** add initial CI configuration ([adbb987](https://git.ext.icikowski.pl/go/collections/commit/adbb987cbd01b21b4b09c7a75801d90f7941fbc7))

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# `collections`
[![Go Report Card](https://goreportcard.com/badge/pkg.icikowski.pl/collections)](https://goreportcard.com/report/pkg.icikowski.pl/collections)
Collections and stream-like operations for Go.

View File

@ -9,7 +9,7 @@ import (
"pkg.icikowski.pl/collections/functions"
)
// Collection represents the collection of data
// Collection represents the collection of data.
//
// By default, the collection uses parallel implementation of operators.
type Collection[T any] struct {
@ -17,23 +17,23 @@ type Collection[T any] struct {
parallel bool
}
// Count counts values in the collection
// Count counts values in the collection.
func (s *Collection[T]) Count() int {
return len(s.data)
}
// Epty determines whether the collection is empty
// Epty determines whether the collection is empty.
func (s *Collection[T]) Empty() bool {
return len(s.data) == 0
}
// Parallel sets the collection to use parallel implementation of operators
// Parallel sets the collection to use parallel implementation of operators.
func (s *Collection[T]) Parallel() *Collection[T] {
s.parallel = true
return s
}
// Sequential sets the collection to use sequential implementation of operators
// Sequential sets the collection to use sequential implementation of operators.
func (s *Collection[T]) Sequential() *Collection[T] {
s.parallel = false
return s
@ -73,7 +73,7 @@ func (s *Collection[T]) filterSequential(p functions.Predicate[T]) *Collection[T
return s
}
// Filter filters the collection using given [functions.Predicate]
// Filter filters the collection using given [functions.Predicate].
func (s *Collection[T]) Filter(p functions.Predicate[T]) *Collection[T] {
if s.parallel {
return s.filterParallel(p)
@ -113,7 +113,7 @@ func (s *Collection[T]) allMatchSequential(p functions.Predicate[T]) bool {
return true
}
// AllMatch checks whether all elements in collection match given [functions.Predicate]
// AllMatch checks whether all elements in collection match given [functions.Predicate].
func (s *Collection[T]) AllMatch(p functions.Predicate[T]) bool {
if s.parallel {
return s.allMatchParallel(p)
@ -153,7 +153,7 @@ func (s *Collection[T]) anyMatchSequential(p functions.Predicate[T]) bool {
return false
}
// AnyMatch checks whether any elements in collection match given [functions.Predicate]
// AnyMatch checks whether any elements in collection match given [functions.Predicate].
func (s *Collection[T]) AnyMatch(p functions.Predicate[T]) bool {
if s.parallel {
return s.anyMatchParallel(p)
@ -193,7 +193,7 @@ func (s *Collection[T]) noneMatchSequential(p functions.Predicate[T]) bool {
return true
}
// NoneMatch checks whether no elements in collection match given [functions.Predicate]
// NoneMatch checks whether no elements in collection match given [functions.Predicate].
func (s *Collection[T]) NoneMatch(p functions.Predicate[T]) bool {
if s.parallel {
return s.noneMatchParallel(p)
@ -201,7 +201,7 @@ func (s *Collection[T]) NoneMatch(p functions.Predicate[T]) bool {
return s.noneMatchSequential(p)
}
// Sorted sorts the collection using given [functions.Comparator]
// Sorted sorts the collection using given [functions.Comparator].
func (s *Collection[T]) Sorted(c functions.Comparator[T]) *Collection[T] {
sort.SliceStable(s.data, func(i, j int) bool {
return c(s.data[i], s.data[j])
@ -232,7 +232,7 @@ func (s *Collection[T]) peekSequential(c functions.Consumer[T]) *Collection[T] {
return s
}
// Peek executes given [function.Consumer] on every value in collections
// Peek executes given [function.Consumer] on every value in collections.
func (s *Collection[T]) Peek(c functions.Consumer[T]) *Collection[T] {
if s.parallel {
return s.peekParallel(c)
@ -267,7 +267,7 @@ func (s *Collection[T]) transformSequential(u functions.UnaryOperator[T]) *Colle
return s
}
// Transform transforms all values in collection using given [functions.UnaryOperator]
// Transform transforms all values in collection using given [functions.UnaryOperator].
func (s *Collection[T]) Transform(u functions.UnaryOperator[T]) *Collection[T] {
if s.parallel {
return s.transformParallel(u)
@ -275,7 +275,7 @@ func (s *Collection[T]) Transform(u functions.UnaryOperator[T]) *Collection[T] {
return s.transformSequential(u)
}
// Reduce reduces values in given collection using given [functions.BinaryOperator]
// Reduce reduces values in given collection using given [functions.BinaryOperator].
func (s *Collection[T]) Reduce(b functions.BinaryOperator[T]) T {
processed := *new(T)
if len(s.data) == 0 {
@ -288,7 +288,7 @@ func (s *Collection[T]) Reduce(b functions.BinaryOperator[T]) T {
return processed
}
// Limit limits the collection to given number of values
// Limit limits the collection to given number of values.
func (s *Collection[T]) Limit(n int) *Collection[T] {
if len(s.data) < n {
return s
@ -302,7 +302,7 @@ func (s *Collection[T]) Limit(n int) *Collection[T] {
return s
}
// Skip skips given number of values in the collection
// Skip skips given number of values in the collection.
func (s *Collection[T]) Skip(n int) *Collection[T] {
if len(s.data) == 0 {
return s
@ -316,7 +316,7 @@ func (s *Collection[T]) Skip(n int) *Collection[T] {
return s
}
// FindFirst returns [Optional] with first item of the collection
// FindFirst returns [Optional] with first item of the collection.
func (s *Collection[T]) FindFirst() *Optional[T] {
e, present := *new(T), false
if len(s.data) != 0 {
@ -325,7 +325,7 @@ func (s *Collection[T]) FindFirst() *Optional[T] {
return &Optional[T]{e, present}
}
// FindFirst returns [Optional] with last item of the collection
// FindFirst returns [Optional] with last item of the collection.
func (s *Collection[T]) FindLast() *Optional[T] {
e, present := *new(T), false
if len(s.data) != 0 {
@ -334,17 +334,17 @@ func (s *Collection[T]) FindLast() *Optional[T] {
return &Optional[T]{e, present}
}
// Min returns the lowest value from the collection using given [functions.Comparator]
// Min returns the lowest value from the collection using given [functions.Comparator].
func (s *Collection[T]) Min(c functions.Comparator[T]) *Optional[T] {
return s.Sorted(c).FindFirst()
}
// Max returns the highest value from the collection using given [functions.Comparator]
// Max returns the highest value from the collection using given [functions.Comparator].
func (s *Collection[T]) Max(c functions.Comparator[T]) *Optional[T] {
return s.Sorted(c).FindLast()
}
// Distinct ensures that all elements in the collecion are unique
// Distinct ensures that all elements in the collecion are unique.
func (s *Collection[T]) Distinct() *Collection[T] {
processed := []T{}
for i := 0; i < len(s.data); i++ {
@ -363,7 +363,7 @@ func (s *Collection[T]) Distinct() *Collection[T] {
return s
}
// MapCollection maps collection of values of type T to collection of values of type U using given [functions.Function]
// MapCollection maps collection of values of type T to collection of values of type U using given [functions.Function].
func MapCollection[T, U any](src *Collection[T], mapper functions.Function[T, U]) *Collection[U] {
data := []U{}
for _, e := range src.data {
@ -372,7 +372,7 @@ func MapCollection[T, U any](src *Collection[T], mapper functions.Function[T, U]
return &Collection[U]{data, src.parallel}
}
// Collect returns all items from collection as a slice
// Collect returns all items from collection as a slice.
func (s *Collection[T]) Collect() []T {
return s.data
}

View File

@ -1,27 +1,27 @@
package collections
import (
"embed"
"strconv"
"strings"
"testing"
_ "embed"
"github.com/stretchr/testify/require"
)
//go:embed collection_test.csv
var testData embed.FS
var testData []byte
type person struct {
func TestCollection(t *testing.T) {
type person struct {
ID int
LastName string
FirstName string
Email string
}
}
func TestCollection(t *testing.T) {
rawData, _ := testData.ReadFile("collection_test.csv")
data := strings.Split(string(rawData), "\n")
data := strings.Split(string(testData), "\n")
lines := OfSlice(data).Skip(1).Filter(func(s string) bool {
return strings.Contains(s, ",")

View File

@ -2,7 +2,7 @@ package comparators
import "pkg.icikowski.pl/collections/functions"
// CompareNumeric returns comparator for numeric values
// CompareNumeric returns comparator for numeric values.
func CompareNumeric[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64]() functions.Comparator[T] {
return func(a, b T) bool {
return a < b

View File

@ -1,4 +1,4 @@
/*
Handy comparators
Handy comparators.
*/
package comparators

View File

@ -6,7 +6,7 @@ import (
"pkg.icikowski.pl/collections/functions"
)
// CompareString returns [functions.Comparator] for string values in given language
// CompareString returns [functions.Comparator] for string values in given language.
func CompareString(lang language.Tag) functions.Comparator[string] {
c := collate.New(lang)
return func(a, b string) bool {

View File

@ -2,17 +2,17 @@ package collections
import "pkg.icikowski.pl/collections/functions"
// Of creates [Collection] of given items
// Of creates [Collection] of given items.
func Of[T any](data ...T) *Collection[T] {
return &Collection[T]{data, true}
}
// OfSlice creates [Collection] of given slice elements
// OfSlice creates [Collection] of given slice elements.
func OfSlice[T any](data []T) *Collection[T] {
return &Collection[T]{data, true}
}
// Iterate creates [Collection] of given number of items generated from given seed and [functions.UnaryOperator]
// Iterate creates [Collection] of given number of items generated from given seed and [functions.UnaryOperator].
func Iterate[T any](seed T, u functions.UnaryOperator[T], limit int) *Collection[T] {
if limit <= 0 {
limit = 1
@ -25,7 +25,7 @@ func Iterate[T any](seed T, u functions.UnaryOperator[T], limit int) *Collection
return &Collection[T]{data, true}
}
// Generate creates [Collection] of given number of items generated from given [functions.Supplier]
// Generate creates [Collection] of given number of items generated from given [functions.Supplier].
func Generate[T any](p functions.Supplier[T], limit int) *Collection[T] {
if limit < 0 {
limit = 0

View File

@ -1,4 +1,4 @@
/*
Function types
Function types.
*/
package functions

View File

@ -1,24 +1,24 @@
package functions
type (
// Consumer takes an argument of type T and returns nothing
// Consumer takes an argument of type T and returns nothing.
Consumer[T any] func(T)
// Function takes an argument of type T and returns a result of type U
// Function takes an argument of type T and returns a result of type U.
Function[T, U any] func(T) U
// Predicate takes an argument of type T and returns a boolean result
// Predicate takes an argument of type T and returns a boolean result.
Predicate[T any] func(T) bool
// Supplier takes no argument and returns a result of type T
// Supplier takes no argument and returns a result of type T.
Supplier[T any] func() T
// UnaryOperator takes an argument of type T and returns a result of type T
// UnaryOperator takes an argument of type T and returns a result of type T.
UnaryOperator[T any] func(T) T
// BinaryOperator takes two arguments of type T and returns a result of type T
// BinaryOperator takes two arguments of type T and returns a result of type T.
BinaryOperator[T any] func(T, T) T
// Comparator takes two arguments of type T and returns a boolean result
// Comparator takes two arguments of type T and returns a boolean result.
Comparator[T any] func(T, T) bool
)

7
go.mod
View File

@ -2,10 +2,13 @@ module pkg.icikowski.pl/collections
go 1.20
require (
github.com/stretchr/testify v1.9.0
golang.org/x/text v0.15.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/text v0.11.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

9
go.sum
View File

@ -2,10 +2,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -2,23 +2,23 @@ package collections
import "pkg.icikowski.pl/collections/functions"
// Optional represents an optional value of type T
// Optional represents an optional value of type T.
type Optional[T any] struct {
e T
present bool
}
// IsPresent determines whether the underlying value is present
// IsPresent determines whether the underlying value is present.
func (o *Optional[T]) IsPresent() bool {
return o.present
}
// Get returns the underlying value
// Get returns the underlying value.
func (o *Optional[T]) Get() T {
return o.e
}
// OrElse returns the underlying value or given value if underlying value is not present
// OrElse returns the underlying value or given value if underlying value is not present.
func (o *Optional[T]) OrElse(e T) T {
if !o.present {
return e
@ -26,7 +26,7 @@ func (o *Optional[T]) OrElse(e T) T {
return o.e
}
// OrElseGet returns the underlying value or value from given supplier if underlying value is not present
// OrElseGet returns the underlying value or value from given supplier if underlying value is not present.
func (o *Optional[T]) OrElseGet(s functions.Supplier[T]) T {
if !o.present {
return s()
@ -34,7 +34,7 @@ func (o *Optional[T]) OrElseGet(s functions.Supplier[T]) T {
return o.e
}
// Transform transforms the underlying value with given [functions.UnaryOperator] if the vale is present
// Transform transforms the underlying value with given [functions.UnaryOperator] if the vale is present.
func (o *Optional[T]) Transform(u functions.UnaryOperator[T]) *Optional[T] {
if o.present {
o.e = u(o.e)
@ -42,7 +42,7 @@ func (o *Optional[T]) Transform(u functions.UnaryOperator[T]) *Optional[T] {
return o
}
// MapOptional maps optional of type T to optional of type U using given [functions.Function]
// MapOptional maps optional of type T to optional of type U using given [functions.Function].
func MapOptional[T, U any](src *Optional[T], mapper functions.Function[T, U]) *Optional[U] {
return &Optional[U]{mapper(src.e), src.present}
}

8219
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/*
Collections-related types and functions
Collections and stream-like operations for Go.
*/
package collections

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"private": true,
"name": "collections",
"version": "0.1.1-rc.11",
"scripts": {
"release": "./node_modules/.bin/semantic-release"
},
"devDependencies": {
"@saithodev/semantic-release-gitea": "^2.1.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^12.0.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^12.0.0",
"@semantic-release/release-notes-generator": "^13.0.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"semantic-release": "^23.0.0"
}
}