summaryrefslogtreecommitdiff
path: root/vendor/github.com/samber
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/samber')
-rw-r--r--vendor/github.com/samber/lo/.gitignore38
-rw-r--r--vendor/github.com/samber/lo/Dockerfile8
-rw-r--r--vendor/github.com/samber/lo/LICENSE21
-rw-r--r--vendor/github.com/samber/lo/Makefile42
-rw-r--r--vendor/github.com/samber/lo/README.md4213
-rw-r--r--vendor/github.com/samber/lo/channel.go314
-rw-r--r--vendor/github.com/samber/lo/concurrency.go136
-rw-r--r--vendor/github.com/samber/lo/condition.go151
-rw-r--r--vendor/github.com/samber/lo/constraints.go6
-rw-r--r--vendor/github.com/samber/lo/errors.go381
-rw-r--r--vendor/github.com/samber/lo/find.go651
-rw-r--r--vendor/github.com/samber/lo/func.go41
-rw-r--r--vendor/github.com/samber/lo/internal/constraints/constraints.go42
-rw-r--r--vendor/github.com/samber/lo/internal/constraints/ordered_go118.go11
-rw-r--r--vendor/github.com/samber/lo/internal/constraints/ordered_go121.go9
-rw-r--r--vendor/github.com/samber/lo/internal/rand/ordered_go118.go26
-rw-r--r--vendor/github.com/samber/lo/internal/rand/ordered_go122.go17
-rw-r--r--vendor/github.com/samber/lo/intersect.go265
-rw-r--r--vendor/github.com/samber/lo/map.go344
-rw-r--r--vendor/github.com/samber/lo/math.go142
-rw-r--r--vendor/github.com/samber/lo/mutable/slice.go71
-rw-r--r--vendor/github.com/samber/lo/retry.go375
-rw-r--r--vendor/github.com/samber/lo/slice.go745
-rw-r--r--vendor/github.com/samber/lo/string.go234
-rw-r--r--vendor/github.com/samber/lo/time.go85
-rw-r--r--vendor/github.com/samber/lo/tuples.go1149
-rw-r--r--vendor/github.com/samber/lo/type_manipulation.go189
-rw-r--r--vendor/github.com/samber/lo/types.go123
28 files changed, 9829 insertions, 0 deletions
diff --git a/vendor/github.com/samber/lo/.gitignore b/vendor/github.com/samber/lo/.gitignore
new file mode 100644
index 00000000..e5ecc5c4
--- /dev/null
+++ b/vendor/github.com/samber/lo/.gitignore
@@ -0,0 +1,38 @@
+
+# Created by https://www.toptal.com/developers/gitignore/api/go
+# Edit at https://www.toptal.com/developers/gitignore?templates=go
+
+### Go ###
+# If you prefer the allow list template instead of the deny list, see community template:
+# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
+#
+# Binaries for programs and plugins
+*.exe
+*.exe~
+*.dll
+*.so
+*.dylib
+
+# Test binary, built with `go test -c`
+*.test
+
+# Output of the go coverage tool, specifically when used with LiteIDE
+*.out
+
+# Dependency directories (remove the comment below to include it)
+# vendor/
+
+# Go workspace file
+go.work
+
+### Go Patch ###
+/vendor/
+/Godeps/
+
+# End of https://www.toptal.com/developers/gitignore/api/go
+
+cover.out
+cover.html
+.vscode
+
+.idea/
diff --git a/vendor/github.com/samber/lo/Dockerfile b/vendor/github.com/samber/lo/Dockerfile
new file mode 100644
index 00000000..5dbeb415
--- /dev/null
+++ b/vendor/github.com/samber/lo/Dockerfile
@@ -0,0 +1,8 @@
+
+FROM golang:1.23.1
+
+WORKDIR /go/src/github.com/samber/lo
+
+COPY Makefile go.* ./
+
+RUN make tools
diff --git a/vendor/github.com/samber/lo/LICENSE b/vendor/github.com/samber/lo/LICENSE
new file mode 100644
index 00000000..2e3ebd5e
--- /dev/null
+++ b/vendor/github.com/samber/lo/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022-2025 Samuel Berthe
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/samber/lo/Makefile b/vendor/github.com/samber/lo/Makefile
new file mode 100644
index 00000000..f97ded85
--- /dev/null
+++ b/vendor/github.com/samber/lo/Makefile
@@ -0,0 +1,42 @@
+
+build:
+ go build -v ./...
+
+test:
+ go test -race -v ./...
+watch-test:
+ reflex -t 50ms -s -- sh -c 'gotest -race -v ./...'
+
+bench:
+ go test -benchmem -count 3 -bench ./...
+watch-bench:
+ reflex -t 50ms -s -- sh -c 'go test -benchmem -count 3 -bench ./...'
+
+coverage:
+ go test -v -coverprofile=cover.out -covermode=atomic ./...
+ go tool cover -html=cover.out -o cover.html
+
+# tools
+tools:
+ go install github.com/cespare/reflex@latest
+ go install github.com/rakyll/gotest@latest
+ go install github.com/psampaz/go-mod-outdated@latest
+ go install github.com/jondot/goweight@latest
+ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
+ go get -t -u golang.org/x/tools/cmd/cover
+ go install github.com/sonatype-nexus-community/nancy@latest
+ go mod tidy
+
+lint:
+ golangci-lint run --timeout 60s --max-same-issues 50 ./...
+lint-fix:
+ golangci-lint run --timeout 60s --max-same-issues 50 --fix ./...
+
+audit: tools
+ go list -json -m all | nancy sleuth
+
+outdated: tools
+ go list -u -m -json all | go-mod-outdated -update -direct
+
+weight: tools
+ goweight
diff --git a/vendor/github.com/samber/lo/README.md b/vendor/github.com/samber/lo/README.md
new file mode 100644
index 00000000..87d25509
--- /dev/null
+++ b/vendor/github.com/samber/lo/README.md
@@ -0,0 +1,4213 @@
+
+# lo - Iterate over slices, maps, channels...
+
+[![tag](https://img.shields.io/github/tag/samber/lo.svg)](https://github.com/samber/lo/releases)
+![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.18-%23007d9c)
+[![GoDoc](https://godoc.org/github.com/samber/lo?status.svg)](https://pkg.go.dev/github.com/samber/lo)
+![Build Status](https://github.com/samber/lo/actions/workflows/test.yml/badge.svg)
+[![Go report](https://goreportcard.com/badge/github.com/samber/lo)](https://goreportcard.com/report/github.com/samber/lo)
+[![Coverage](https://img.shields.io/codecov/c/github/samber/lo)](https://codecov.io/gh/samber/lo)
+[![Contributors](https://img.shields.io/github/contributors/samber/lo)](https://github.com/samber/lo/graphs/contributors)
+[![License](https://img.shields.io/github/license/samber/lo)](./LICENSE)
+
+✨ **`samber/lo` is a Lodash-style Go library based on Go 1.18+ Generics.**
+
+A utility library based on Go 1.18+ generics that makes it easier to work with slices, maps, strings, channels, and functions. It provides dozens of handy methods to simplify common coding tasks and improve code readability. It may look like [Lodash](https://github.com/lodash/lodash) in some aspects.
+
+5 to 10 helpers may overlap with those from the Go standard library, in packages `slices` and `maps`. I feel this library is legitimate and offers many more valuable abstractions.
+
+**See also:**
+
+- [samber/do](https://github.com/samber/do): A dependency injection toolkit based on Go 1.18+ Generics
+- [samber/mo](https://github.com/samber/mo): Monads based on Go 1.18+ Generics (Option, Result, Either...)
+
+**Why this name?**
+
+I wanted a **short name**, similar to "Lodash", and no Go package uses this name.
+
+![lo](img/logo-full.png)
+
+## 🚀 Install
+
+```sh
+go get github.com/samber/lo@v1
+```
+
+This library is v1 and follows SemVer strictly.
+
+No breaking changes will be made to exported APIs before v2.0.0.
+
+This library has no dependencies outside the Go standard library.
+
+## 💡 Usage
+
+You can import `lo` using:
+
+```go
+import (
+ "github.com/samber/lo"
+ lop "github.com/samber/lo/parallel"
+ lom "github.com/samber/lo/mutable"
+)
+```
+
+Then use one of the helpers below:
+
+```go
+names := lo.Uniq([]string{"Samuel", "John", "Samuel"})
+// []string{"Samuel", "John"}
+```
+
+### Tips for lazy developers
+
+I cannot recommend it, but in case you are too lazy for repeating `lo.` everywhere, you can import the entire library into the namespace.
+
+```go
+import (
+ . "github.com/samber/lo"
+)
+```
+
+I take no responsibility on this junk. 😁 💩
+
+## 🤠 Spec
+
+GoDoc: [https://godoc.org/github.com/samber/lo](https://godoc.org/github.com/samber/lo)
+
+Supported helpers for slices:
+
+- [Filter](#filter)
+- [Map](#map)
+- [UniqMap](#uniqmap)
+- [FilterMap](#filtermap)
+- [FlatMap](#flatmap)
+- [Reduce](#reduce)
+- [ReduceRight](#reduceright)
+- [ForEach](#foreach)
+- [ForEachWhile](#foreachwhile)
+- [Times](#times)
+- [Uniq](#uniq)
+- [UniqBy](#uniqby)
+- [GroupBy](#groupby)
+- [GroupByMap](#groupbymap)
+- [Chunk](#chunk)
+- [PartitionBy](#partitionby)
+- [Flatten](#flatten)
+- [Interleave](#interleave)
+- [Shuffle](#shuffle)
+- [Reverse](#reverse)
+- [Fill](#fill)
+- [Repeat](#repeat)
+- [RepeatBy](#repeatby)
+- [KeyBy](#keyby)
+- [SliceToMap / Associate](#slicetomap-alias-associate)
+- [FilterSliceToMap](#filterslicetomap)
+- [Keyify](#keyify)
+- [Drop](#drop)
+- [DropRight](#dropright)
+- [DropWhile](#dropwhile)
+- [DropRightWhile](#droprightwhile)
+- [DropByIndex](#DropByIndex)
+- [Reject](#reject)
+- [RejectMap](#rejectmap)
+- [FilterReject](#filterreject)
+- [Count](#count)
+- [CountBy](#countby)
+- [CountValues](#countvalues)
+- [CountValuesBy](#countvaluesby)
+- [Subset](#subset)
+- [Slice](#slice)
+- [Replace](#replace)
+- [ReplaceAll](#replaceall)
+- [Compact](#compact)
+- [IsSorted](#issorted)
+- [IsSortedByKey](#issortedbykey)
+- [Splice](#Splice)
+
+Supported helpers for maps:
+
+- [Keys](#keys)
+- [UniqKeys](#uniqkeys)
+- [HasKey](#haskey)
+- [ValueOr](#valueor)
+- [Values](#values)
+- [UniqValues](#uniqvalues)
+- [PickBy](#pickby)
+- [PickByKeys](#pickbykeys)
+- [PickByValues](#pickbyvalues)
+- [OmitBy](#omitby)
+- [OmitByKeys](#omitbykeys)
+- [OmitByValues](#omitbyvalues)
+- [Entries / ToPairs](#entries-alias-topairs)
+- [FromEntries / FromPairs](#fromentries-alias-frompairs)
+- [Invert](#invert)
+- [Assign (merge of maps)](#assign)
+- [MapKeys](#mapkeys)
+- [MapValues](#mapvalues)
+- [MapEntries](#mapentries)
+- [MapToSlice](#maptoslice)
+- [FilterMapToSlice](#FilterMapToSlice)
+
+Supported math helpers:
+
+- [Range / RangeFrom / RangeWithSteps](#range--rangefrom--rangewithsteps)
+- [Clamp](#clamp)
+- [Sum](#sum)
+- [SumBy](#sumby)
+- [Product](#product)
+- [ProductBy](#productby)
+- [Mean](#mean)
+- [MeanBy](#meanby)
+
+Supported helpers for strings:
+
+- [RandomString](#randomstring)
+- [Substring](#substring)
+- [ChunkString](#chunkstring)
+- [RuneLength](#runelength)
+- [PascalCase](#pascalcase)
+- [CamelCase](#camelcase)
+- [KebabCase](#kebabcase)
+- [SnakeCase](#snakecase)
+- [Words](#words)
+- [Capitalize](#capitalize)
+- [Ellipsis](#ellipsis)
+
+Supported helpers for tuples:
+
+- [T2 -> T9](#t2---t9)
+- [Unpack2 -> Unpack9](#unpack2---unpack9)
+- [Zip2 -> Zip9](#zip2---zip9)
+- [ZipBy2 -> ZipBy9](#zipby2---zipby9)
+- [Unzip2 -> Unzip9](#unzip2---unzip9)
+- [UnzipBy2 -> UnzipBy9](#unzipby2---unzipby9)
+- [CrossJoin2 -> CrossJoin2](#crossjoin2---crossjoin9)
+- [CrossJoinBy2 -> CrossJoinBy2](#crossjoinby2---crossjoinby9)
+
+Supported helpers for time and duration:
+
+- [Duration](#duration)
+- [Duration0 -> Duration10](#duration0---duration10)
+
+Supported helpers for channels:
+
+- [ChannelDispatcher](#channeldispatcher)
+- [SliceToChannel](#slicetochannel)
+- [Generator](#generator)
+- [Buffer](#buffer)
+- [BufferWithContext](#bufferwithcontext)
+- [BufferWithTimeout](#bufferwithtimeout)
+- [FanIn](#fanin)
+- [FanOut](#fanout)
+
+Supported intersection helpers:
+
+- [Contains](#contains)
+- [ContainsBy](#containsby)
+- [Every](#every)
+- [EveryBy](#everyby)
+- [Some](#some)
+- [SomeBy](#someby)
+- [None](#none)
+- [NoneBy](#noneby)
+- [Intersect](#intersect)
+- [Difference](#difference)
+- [Union](#union)
+- [Without](#without)
+- [WithoutBy](#withoutby)
+- [WithoutEmpty](#withoutempty)
+- [WithoutNth](#withoutnth)
+- [ElementsMatch](#ElementsMatch)
+- [ElementsMatchBy](#ElementsMatchBy)
+
+Supported search helpers:
+
+- [IndexOf](#indexof)
+- [LastIndexOf](#lastindexof)
+- [Find](#find)
+- [FindIndexOf](#findindexof)
+- [FindLastIndexOf](#findlastindexof)
+- [FindOrElse](#findorelse)
+- [FindKey](#findkey)
+- [FindKeyBy](#findkeyby)
+- [FindUniques](#finduniques)
+- [FindUniquesBy](#finduniquesby)
+- [FindDuplicates](#findduplicates)
+- [FindDuplicatesBy](#findduplicatesby)
+- [Min](#min)
+- [MinIndex](#minindex)
+- [MinBy](#minby)
+- [MinIndexBy](#minindexby)
+- [Earliest](#earliest)
+- [EarliestBy](#earliestby)
+- [Max](#max)
+- [MaxIndex](#maxindex)
+- [MaxBy](#maxby)
+- [MaxIndexBy](#maxindexby)
+- [Latest](#latest)
+- [LatestBy](#latestby)
+- [First](#first)
+- [FirstOrEmpty](#FirstOrEmpty)
+- [FirstOr](#FirstOr)
+- [Last](#last)
+- [LastOrEmpty](#LastOrEmpty)
+- [LastOr](#LastOr)
+- [Nth](#nth)
+- [NthOr](#nthor)
+- [NthOrEmpty](#nthorempty)
+- [Sample](#sample)
+- [SampleBy](#sampleby)
+- [Samples](#samples)
+- [SamplesBy](#samplesby)
+
+Conditional helpers:
+
+- [Ternary](#ternary)
+- [TernaryF](#ternaryf)
+- [If / ElseIf / Else](#if--elseif--else)
+- [Switch / Case / Default](#switch--case--default)
+
+Type manipulation helpers:
+
+- [IsNil](#isnil)
+- [IsNotNil](#isnotnil)
+- [ToPtr](#toptr)
+- [Nil](#nil)
+- [EmptyableToPtr](#emptyabletoptr)
+- [FromPtr](#fromptr)
+- [FromPtrOr](#fromptror)
+- [ToSlicePtr](#tosliceptr)
+- [FromSlicePtr](#fromsliceptr)
+- [FromSlicePtrOr](#fromsliceptror)
+- [ToAnySlice](#toanyslice)
+- [FromAnySlice](#fromanyslice)
+- [Empty](#empty)
+- [IsEmpty](#isempty)
+- [IsNotEmpty](#isnotempty)
+- [Coalesce](#coalesce)
+- [CoalesceOrEmpty](#coalesceorempty)
+- [CoalesceSlice](#coalesceslice)
+- [CoalesceSliceOrEmpty](#coalescesliceorempty)
+- [CoalesceMap](#coalescemap)
+- [CoalesceMapOrEmpty](#coalescemaporempty)
+
+Function helpers:
+
+- [Partial](#partial)
+- [Partial2 -> Partial5](#partial2---partial5)
+
+Concurrency helpers:
+
+- [Attempt](#attempt)
+- [AttemptWhile](#attemptwhile)
+- [AttemptWithDelay](#attemptwithdelay)
+- [AttemptWhileWithDelay](#attemptwhilewithdelay)
+- [Debounce](#debounce)
+- [DebounceBy](#debounceby)
+- [Throttle](#throttle)
+- [ThrottleWithCount](#throttle)
+- [ThrottleBy](#throttle)
+- [ThrottleByWithCount](#throttle)
+- [Synchronize](#synchronize)
+- [Async](#async)
+- [Transaction](#transaction)
+- [WaitFor](#waitfor)
+- [WaitForWithContext](#waitforwithcontext)
+
+Error handling:
+
+- [Validate](#validate)
+- [Must](#must)
+- [Try](#try)
+- [Try1 -> Try6](#try0-6)
+- [TryOr](#tryor)
+- [TryOr1 -> TryOr6](#tryor0-6)
+- [TryCatch](#trycatch)
+- [TryWithErrorValue](#trywitherrorvalue)
+- [TryCatchWithErrorValue](#trycatchwitherrorvalue)
+- [ErrorsAs](#errorsas)
+- [Assert](#assert)
+- [Assertf](#assertf)
+
+Constraints:
+
+- Clonable
+
+### Filter
+
+Iterates over a collection and returns an array of all the elements the predicate function returns `true` for.
+
+```go
+even := lo.Filter([]int{1, 2, 3, 4}, func(x int, index int) bool {
+ return x%2 == 0
+})
+// []int{2, 4}
+```
+
+[[play](https://go.dev/play/p/Apjg3WeSi7K)]
+
+Mutable: like `lo.Filter()`, but the slice is updated in place.
+
+```go
+import lom "github.com/samber/lo/mutable"
+
+list := []int{1, 2, 3, 4}
+newList := lom.Filter(list, func(x int) bool {
+ return x%2 == 0
+})
+
+list
+// []int{2, 4, 3, 4}
+
+newList
+// []int{2, 4}
+```
+
+### Map
+
+Manipulates a slice of one type and transforms it into a slice of another type:
+
+```go
+import "github.com/samber/lo"
+
+lo.Map([]int64{1, 2, 3, 4}, func(x int64, index int) string {
+ return strconv.FormatInt(x, 10)
+})
+// []string{"1", "2", "3", "4"}
+```
+
+[[play](https://go.dev/play/p/OkPcYAhBo0D)]
+
+Parallel processing: like `lo.Map()`, but the mapper function is called in a goroutine. Results are returned in the same order.
+
+```go
+import lop "github.com/samber/lo/parallel"
+
+lop.Map([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
+ return strconv.FormatInt(x, 10)
+})
+// []string{"1", "2", "3", "4"}
+```
+
+Mutable: like `lo.Map()`, but the slice is updated in place.
+
+```go
+import lom "github.com/samber/lo/mutable"
+
+list := []int{1, 2, 3, 4}
+lom.Map(list, func(x int) int {
+ return x*2
+})
+// []int{2, 4, 6, 8}
+```
+
+### UniqMap
+
+Manipulates a slice and transforms it to a slice of another type with unique values.
+
+```go
+type User struct {
+ Name string
+ Age int
+}
+users := []User{{Name: "Alex", Age: 10}, {Name: "Alex", Age: 12}, {Name: "Bob", Age: 11}, {Name: "Alice", Age: 20}}
+
+names := lo.UniqMap(users, func(u User, index int) string {
+ return u.Name
+})
+// []string{"Alex", "Bob", "Alice"}
+```
+
+### FilterMap
+
+Returns a slice which obtained after both filtering and mapping using the given callback function.
+
+The callback function should return two values: the result of the mapping operation and whether the result element should be included or not.
+
+```go
+matching := lo.FilterMap([]string{"cpu", "gpu", "mouse", "keyboard"}, func(x string, _ int) (string, bool) {
+ if strings.HasSuffix(x, "pu") {
+ return "xpu", true
+ }
+ return "", false
+})
+// []string{"xpu", "xpu"}
+```
+
+[[play](https://go.dev/play/p/-AuYXfy7opz)]
+
+### FlatMap
+
+Manipulates a slice and transforms and flattens it to a slice of another type. The transform function can either return a slice or a `nil`, and in the `nil` case no value is added to the final slice.
+
+```go
+lo.FlatMap([]int64{0, 1, 2}, func(x int64, _ int) []string {
+ return []string{
+ strconv.FormatInt(x, 10),
+ strconv.FormatInt(x, 10),
+ }
+})
+// []string{"0", "0", "1", "1", "2", "2"}
+```
+
+[[play](https://go.dev/play/p/YSoYmQTA8-U)]
+
+### Reduce
+
+Reduces a collection to a single value. The value is calculated by accumulating the result of running each element in the collection through an accumulator function. Each successive invocation is supplied with the return value returned by the previous call.
+
+```go
+sum := lo.Reduce([]int{1, 2, 3, 4}, func(agg int, item int, _ int) int {
+ return agg + item
+}, 0)
+// 10
+```
+
+[[play](https://go.dev/play/p/R4UHXZNaaUG)]
+
+### ReduceRight
+
+Like `lo.Reduce` except that it iterates over elements of collection from right to left.
+
+```go
+result := lo.ReduceRight([][]int{{0, 1}, {2, 3}, {4, 5}}, func(agg []int, item []int, _ int) []int {
+ return append(agg, item...)
+}, []int{})
+// []int{4, 5, 2, 3, 0, 1}
+```
+
+[[play](https://go.dev/play/p/Fq3W70l7wXF)]
+
+### ForEach
+
+Iterates over elements of a collection and invokes the function over each element.
+
+```go
+import "github.com/samber/lo"
+
+lo.ForEach([]string{"hello", "world"}, func(x string, _ int) {
+ println(x)
+})
+// prints "hello\nworld\n"
+```
+
+[[play](https://go.dev/play/p/oofyiUPRf8t)]
+
+Parallel processing: like `lo.ForEach()`, but the callback is called as a goroutine.
+
+```go
+import lop "github.com/samber/lo/parallel"
+
+lop.ForEach([]string{"hello", "world"}, func(x string, _ int) {
+ println(x)
+})
+// prints "hello\nworld\n" or "world\nhello\n"
+```
+
+### ForEachWhile
+
+Iterates over collection elements and invokes iteratee for each element collection return value decide to continue or break, like do while().
+
+```go
+list := []int64{1, 2, -42, 4}
+
+lo.ForEachWhile(list, func(x int64, _ int) bool {
+ if x < 0 {
+ return false
+ }
+ fmt.Println(x)
+ return true
+})
+// 1
+// 2
+```
+
+[[play](https://go.dev/play/p/QnLGt35tnow)]
+
+### Times
+
+Times invokes the iteratee n times, returning an array of the results of each invocation. The iteratee is invoked with index as argument.
+
+```go
+import "github.com/samber/lo"
+
+lo.Times(3, func(i int) string {
+ return strconv.FormatInt(int64(i), 10)
+})
+// []string{"0", "1", "2"}
+```
+
+[[play](https://go.dev/play/p/vgQj3Glr6lT)]
+
+Parallel processing: like `lo.Times()`, but callback is called in goroutine.
+
+```go
+import lop "github.com/samber/lo/parallel"
+
+lop.Times(3, func(i int) string {
+ return strconv.FormatInt(int64(i), 10)
+})
+// []string{"0", "1", "2"}
+```
+
+### Uniq
+
+Returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.
+
+```go
+uniqValues := lo.Uniq([]int{1, 2, 2, 1})
+// []int{1, 2}
+```
+
+[[play](https://go.dev/play/p/DTzbeXZ6iEN)]
+
+### UniqBy
+
+Returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed.
+
+```go
+uniqValues := lo.UniqBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
+ return i%3
+})
+// []int{0, 1, 2}
+```
+
+[[play](https://go.dev/play/p/g42Z3QSb53u)]
+
+### GroupBy
+
+Returns an object composed of keys generated from the results of running each element of collection through iteratee.
+
+```go
+import lo "github.com/samber/lo"
+
+groups := lo.GroupBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
+ return i%3
+})
+// map[int][]int{0: []int{0, 3}, 1: []int{1, 4}, 2: []int{2, 5}}
+```
+
+[[play](https://go.dev/play/p/XnQBd_v6brd)]
+
+Parallel processing: like `lo.GroupBy()`, but callback is called in goroutine.
+
+```go
+import lop "github.com/samber/lo/parallel"
+
+lop.GroupBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
+ return i%3
+})
+// map[int][]int{0: []int{0, 3}, 1: []int{1, 4}, 2: []int{2, 5}}
+```
+
+### GroupByMap
+
+Returns an object composed of keys generated from the results of running each element of collection through iteratee.
+
+```go
+import lo "github.com/samber/lo"
+
+groups := lo.GroupByMap([]int{0, 1, 2, 3, 4, 5}, func(i int) (int, int) {
+ return i%3, i*2
+})
+// map[int][]int{0: []int{0, 6}, 1: []int{2, 8}, 2: []int{4, 10}}
+```
+
+### Chunk
+
+Returns an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
+
+```go
+lo.Chunk([]int{0, 1, 2, 3, 4, 5}, 2)
+// [][]int{{0, 1}, {2, 3}, {4, 5}}
+
+lo.Chunk([]int{0, 1, 2, 3, 4, 5, 6}, 2)
+// [][]int{{0, 1}, {2, 3}, {4, 5}, {6}}
+
+lo.Chunk([]int{}, 2)
+// [][]int{}
+
+lo.Chunk([]int{0}, 2)
+// [][]int{{0}}
+```
+
+[[play](https://go.dev/play/p/EeKl0AuTehH)]
+
+### PartitionBy
+
+Returns an array of elements split into groups. The order of grouped values is determined by the order they occur in collection. The grouping is generated from the results of running each element of collection through iteratee.
+
+```go
+import lo "github.com/samber/lo"
+
+partitions := lo.PartitionBy([]int{-2, -1, 0, 1, 2, 3, 4, 5}, func(x int) string {
+ if x < 0 {
+ return "negative"
+ } else if x%2 == 0 {
+ return "even"
+ }
+ return "odd"
+})
+// [][]int{{-2, -1}, {0, 2, 4}, {1, 3, 5}}
+```
+
+[[play](https://go.dev/play/p/NfQ_nGjkgXW)]
+
+Parallel processing: like `lo.PartitionBy()`, but callback is called in goroutine. Results are returned in the same order.
+
+```go
+import lop "github.com/samber/lo/parallel"
+
+partitions := lop.PartitionBy([]int{-2, -1, 0, 1, 2, 3, 4, 5}, func(x int) string {
+ if x < 0 {
+ return "negative"
+ } else if x%2 == 0 {
+ return "even"
+ }
+ return "odd"
+})
+// [][]int{{-2, -1}, {0, 2, 4}, {1, 3, 5}}
+```
+
+### Flatten
+
+Returns an array a single level deep.
+
+```go
+flat := lo.Flatten([][]int{{0, 1}, {2, 3, 4, 5}})
+// []int{0, 1, 2, 3, 4, 5}
+```
+
+[[play](https://go.dev/play/p/rbp9ORaMpjw)]
+
+### Interleave
+
+Round-robin alternating input slices and sequentially appending value at index into result.
+
+```go
+interleaved := lo.Interleave([]int{1, 4, 7}, []int{2, 5, 8}, []int{3, 6, 9})
+// []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
+
+interleaved := lo.Interleave([]int{1}, []int{2, 5, 8}, []int{3, 6}, []int{4, 7, 9, 10})
+// []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+```
+
+[[play](https://go.dev/play/p/-RJkTLQEDVt)]
+
+### Shuffle
+
+Returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm.
+
+⚠️ This helper is **mutable**.
+
+```go
+import lom "github.com/samber/lo/mutable"
+
+list := []int{0, 1, 2, 3, 4, 5}
+lom.Shuffle(list)
+
+list
+// []int{1, 4, 0, 3, 5, 2}
+```
+
+[[play](https://go.dev/play/p/2xb3WdLjeSJ)]
+
+### Reverse
+
+Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
+
+⚠️ This helper is **mutable**.
+
+```go
+import lom "github.com/samber/lo/mutable"
+
+list := []int{0, 1, 2, 3, 4, 5}
+lom.Reverse(list)
+
+list
+// []int{5, 4, 3, 2, 1, 0}
+```
+
+[[play](https://go.dev/play/p/O-M5pmCRgzV)]
+
+### Fill
+
+Fills elements of array with `initial` value.
+
+```go
+type foo struct {
+ bar string
+}
+
+func (f foo) Clone() foo {
+ return foo{f.bar}
+}
+
+initializedSlice := lo.Fill([]foo{foo{"a"}, foo{"a"}}, foo{"b"})
+// []foo{foo{"b"}, foo{"b"}}
+```
+
+[[play](https://go.dev/play/p/VwR34GzqEub)]
+
+### Repeat
+
+Builds a slice with N copies of initial value.
+
+```go
+type foo struct {
+ bar string
+}
+
+func (f foo) Clone() foo {
+ return foo{f.bar}
+}
+
+slice := lo.Repeat(2, foo{"a"})
+// []foo{foo{"a"}, foo{"a"}}
+```
+
+[[play](https://go.dev/play/p/g3uHXbmc3b6)]
+
+### RepeatBy
+
+Builds a slice with values returned by N calls of callback.
+
+```go
+slice := lo.RepeatBy(0, func (i int) string {
+ return strconv.FormatInt(int64(math.Pow(float64(i), 2)), 10)
+})
+// []string{}
+
+slice := lo.RepeatBy(5, func(i int) string {
+ return strconv.FormatInt(int64(math.Pow(float64(i), 2)), 10)
+})
+// []string{"0", "1", "4", "9", "16"}
+```
+
+[[play](https://go.dev/play/p/ozZLCtX_hNU)]
+
+### KeyBy
+
+Transforms a slice or an array of structs to a map based on a pivot callback.
+
+```go
+m := lo.KeyBy([]string{"a", "aa", "aaa"}, func(str string) int {
+ return len(str)
+})
+// map[int]string{1: "a", 2: "aa", 3: "aaa"}
+
+type Character struct {
+ dir string
+ code int
+}
+characters := []Character{
+ {dir: "left", code: 97},
+ {dir: "right", code: 100},
+}
+result := lo.KeyBy(characters, func(char Character) string {
+ return string(rune(char.code))
+})
+//map[a:{dir:left code:97} d:{dir:right code:100}]
+```
+
+[[play](https://go.dev/play/p/mdaClUAT-zZ)]
+
+### SliceToMap (alias: Associate)
+
+Returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
+If any of two pairs would have the same key the last one gets added to the map.
+
+The order of keys in returned map is not specified and is not guaranteed to be the same from the original array.
+
+```go
+in := []*foo{{baz: "apple", bar: 1}, {baz: "banana", bar: 2}}
+
+aMap := lo.SliceToMap(in, func (f *foo) (string, int) {
+ return f.baz, f.bar
+})
+// map[string][int]{ "apple":1, "banana":2 }
+```
+
+[[play](https://go.dev/play/p/WHa2CfMO3Lr)]
+
+### FilterSliceToMap
+
+Returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
+
+If any of two pairs would have the same key the last one gets added to the map.
+
+The order of keys in returned map is not specified and is not guaranteed to be the same from the original array.
+
+The third return value of the transform function is a boolean that indicates whether the key-value pair should be included in the map.
+
+
+```go
+list := []string{"a", "aa", "aaa"}
+
+result := lo.FilterSliceToMap(list, func(str string) (string, int, bool) {
+ return str, len(str), len(str) > 1
+})
+// map[string][int]{"aa":2 "aaa":3}
+```
+
+### Keyify
+
+Returns a map with each unique element of the slice as a key.
+
+```go
+set := lo.Keyify([]int{1, 1, 2, 3, 4})
+// map[int]struct{}{1:{}, 2:{}, 3:{}, 4:{}}
+```
+
+### Drop
+
+Drops n elements from the beginning of a slice or array.
+
+```go
+l := lo.Drop([]int{0, 1, 2, 3, 4, 5}, 2)
+// []int{2, 3, 4, 5}
+```
+
+[[play](https://go.dev/play/p/JswS7vXRJP2)]
+
+### DropRight
+
+Drops n elements from the end of a slice or array.
+
+```go
+l := lo.DropRight([]int{0, 1, 2, 3, 4, 5}, 2)
+// []int{0, 1, 2, 3}
+```
+
+[[play](https://go.dev/play/p/GG0nXkSJJa3)]
+
+### DropWhile
+
+Drop elements from the beginning of a slice or array while the predicate returns true.
+
+```go
+l := lo.DropWhile([]string{"a", "aa", "aaa", "aa", "aa"}, func(val string) bool {
+ return len(val) <= 2
+})
+// []string{"aaa", "aa", "aa"}
+```
+
+[[play](https://go.dev/play/p/7gBPYw2IK16)]
+
+### DropRightWhile
+
+Drop elements from the end of a slice or array while the predicate returns true.
+
+```go
+l := lo.DropRightWhile([]string{"a", "aa", "aaa", "aa", "aa"}, func(val string) bool {
+ return len(val) <= 2
+})
+// []string{"a", "aa", "aaa"}
+```
+
+[[play](https://go.dev/play/p/3-n71oEC0Hz)]
+
+### DropByIndex
+
+Drops elements from a slice or array by the index. A negative index will drop elements from the end of the slice.
+
+```go
+l := lo.DropByIndex([]int{0, 1, 2, 3, 4, 5}, 2, 4, -1)
+// []int{0, 1, 3}
+```
+
+[[play](https://go.dev/play/p/JswS7vXRJP2)]
+
+### Reject
+
+The opposite of Filter, this method returns the elements of collection that predicate does not return truthy for.
+
+```go
+odd := lo.Reject([]int{1, 2, 3, 4}, func(x int, _ int) bool {
+ return x%2 == 0
+})
+// []int{1, 3}
+```
+
+[[play](https://go.dev/play/p/YkLMODy1WEL)]
+
+### RejectMap
+
+The opposite of FilterMap, this method returns a slice which obtained after both filtering and mapping using the given callback function.
+
+The callback function should return two values:
+
+- the result of the mapping operation and
+- whether the result element should be included or not.
+
+```go
+items := lo.RejectMap([]int{1, 2, 3, 4}, func(x int, _ int) (int, bool) {
+ return x*10, x%2 == 0
+})
+// []int{10, 30}
+```
+
+### FilterReject
+
+Mixes Filter and Reject, this method returns two slices, one for the elements of collection that predicate returns truthy for and one for the elements that predicate does not return truthy for.
+
+```go
+kept, rejected := lo.FilterReject([]int{1, 2, 3, 4}, func(x int, _ int) bool {
+ return x%2 == 0
+})
+// []int{2, 4}
+// []int{1, 3}
+```
+
+### Count
+
+Counts the number of elements in the collection that compare equal to value.
+
+```go
+count := lo.Count([]int{1, 5, 1}, 1)
+// 2
+```
+
+[[play](https://go.dev/play/p/Y3FlK54yveC)]
+
+### CountBy
+
+Counts the number of elements in the collection for which predicate is true.
+
+```go
+count := lo.CountBy([]int{1, 5, 1}, func(i int) bool {
+ return i < 4
+})
+// 2
+```
+
+[[play](https://go.dev/play/p/ByQbNYQQi4X)]
+
+### CountValues
+
+Counts the number of each element in the collection.
+
+```go
+lo.CountValues([]int{})
+// map[int]int{}
+
+lo.CountValues([]int{1, 2})
+// map[int]int{1: 1, 2: 1}
+
+lo.CountValues([]int{1, 2, 2})
+// map[int]int{1: 1, 2: 2}
+
+lo.CountValues([]string{"foo", "bar", ""})
+// map[string]int{"": 1, "foo": 1, "bar": 1}
+
+lo.CountValues([]string{"foo", "bar", "bar"})
+// map[string]int{"foo": 1, "bar": 2}
+```
+
+[[play](https://go.dev/play/p/-p-PyLT4dfy)]
+
+### CountValuesBy
+
+Counts the number of each element in the collection. It ss equivalent to chaining lo.Map and lo.CountValues.
+
+```go
+isEven := func(v int) bool {
+ return v%2==0
+}
+
+lo.CountValuesBy([]int{}, isEven)
+// map[bool]int{}
+
+lo.CountValuesBy([]int{1, 2}, isEven)
+// map[bool]int{false: 1, true: 1}
+
+lo.CountValuesBy([]int{1, 2, 2}, isEven)
+// map[bool]int{false: 1, true: 2}
+
+length := func(v string) int {
+ return len(v)
+}
+
+lo.CountValuesBy([]string{"foo", "bar", ""}, length)
+// map[int]int{0: 1, 3: 2}
+
+lo.CountValuesBy([]string{"foo", "bar", "bar"}, length)
+// map[int]int{3: 3}
+```
+
+[[play](https://go.dev/play/p/2U0dG1SnOmS)]
+
+### Subset
+
+Returns a copy of a slice from `offset` up to `length` elements. Like `slice[start:start+length]`, but does not panic on overflow.
+
+```go
+in := []int{0, 1, 2, 3, 4}
+
+sub := lo.Subset(in, 2, 3)
+// []int{2, 3, 4}
+
+sub := lo.Subset(in, -4, 3)
+// []int{1, 2, 3}
+
+sub := lo.Subset(in, -2, math.MaxUint)
+// []int{3, 4}
+```
+
+[[play](https://go.dev/play/p/tOQu1GhFcog)]
+
+### Slice
+
+Returns a copy of a slice from `start` up to, but not including `end`. Like `slice[start:end]`, but does not panic on overflow.
+
+```go
+in := []int{0, 1, 2, 3, 4}
+
+slice := lo.Slice(in, 0, 5)
+// []int{0, 1, 2, 3, 4}
+
+slice := lo.Slice(in, 2, 3)
+// []int{2}
+
+slice := lo.Slice(in, 2, 6)
+// []int{2, 3, 4}
+
+slice := lo.Slice(in, 4, 3)
+// []int{}
+```
+
+[[play](https://go.dev/play/p/8XWYhfMMA1h)]
+
+### Replace
+
+Returns a copy of the slice with the first n non-overlapping instances of old replaced by new.
+
+```go
+in := []int{0, 1, 0, 1, 2, 3, 0}
+
+slice := lo.Replace(in, 0, 42, 1)
+// []int{42, 1, 0, 1, 2, 3, 0}
+
+slice := lo.Replace(in, -1, 42, 1)
+// []int{0, 1, 0, 1, 2, 3, 0}
+
+slice := lo.Replace(in, 0, 42, 2)
+// []int{42, 1, 42, 1, 2, 3, 0}
+
+slice := lo.Replace(in, 0, 42, -1)
+// []int{42, 1, 42, 1, 2, 3, 42}
+```
+
+[[play](https://go.dev/play/p/XfPzmf9gql6)]
+
+### ReplaceAll
+
+Returns a copy of the slice with all non-overlapping instances of old replaced by new.
+
+```go
+in := []int{0, 1, 0, 1, 2, 3, 0}
+
+slice := lo.ReplaceAll(in, 0, 42)
+// []int{42, 1, 42, 1, 2, 3, 42}
+
+slice := lo.ReplaceAll(in, -1, 42)
+// []int{0, 1, 0, 1, 2, 3, 0}
+```
+
+[[play](https://go.dev/play/p/a9xZFUHfYcV)]
+
+### Compact
+
+Returns a slice of all non-zero elements.
+
+```go
+in := []string{"", "foo", "", "bar", ""}
+
+slice := lo.Compact(in)
+// []string{"foo", "bar"}
+```
+
+[[play](https://go.dev/play/p/tXiy-iK6PAc)]
+
+### IsSorted
+
+Checks if a slice is sorted.
+
+```go
+slice := lo.IsSorted([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
+// true
+```
+
+[[play](https://go.dev/play/p/mc3qR-t4mcx)]
+
+### IsSortedByKey
+
+Checks if a slice is sorted by iteratee.
+
+```go
+slice := lo.IsSortedByKey([]string{"a", "bb", "ccc"}, func(s string) int {
+ return len(s)
+})
+// true
+```
+
+[[play](https://go.dev/play/p/wiG6XyBBu49)]
+
+### Splice
+
+Splice inserts multiple elements at index i. A negative index counts back from the end of the slice. The helper is protected against overflow errors.
+
+```go
+result := lo.Splice([]string{"a", "b"}, 1, "1", "2")
+// []string{"a", "1", "2", "b"}
+
+// negative
+result = lo.Splice([]string{"a", "b"}, -1, "1", "2")
+// []string{"a", "1", "2", "b"}
+
+// overflow
+result = lo.Splice([]string{"a", "b"}, 42, "1", "2")
+// []string{"a", "b", "1", "2"}
+```
+
+[[play](https://go.dev/play/p/wiG6XyBBu49)]
+
+### Keys
+
+Creates a slice of the map keys.
+
+Use the UniqKeys variant to deduplicate common keys.
+
+```go
+keys := lo.Keys(map[string]int{"foo": 1, "bar": 2})
+// []string{"foo", "bar"}
+
+keys := lo.Keys(map[string]int{"foo": 1, "bar": 2}, map[string]int{"baz": 3})
+// []string{"foo", "bar", "baz"}
+
+keys := lo.Keys(map[string]int{"foo": 1, "bar": 2}, map[string]int{"bar": 3})
+// []string{"foo", "bar", "bar"}
+```
+
+[[play](https://go.dev/play/p/Uu11fHASqrU)]
+
+### UniqKeys
+
+Creates an array of unique map keys.
+
+```go
+keys := lo.UniqKeys(map[string]int{"foo": 1, "bar": 2}, map[string]int{"baz": 3})
+// []string{"foo", "bar", "baz"}
+
+keys := lo.UniqKeys(map[string]int{"foo": 1, "bar": 2}, map[string]int{"bar": 3})
+// []string{"foo", "bar"}
+```
+
+[[play](https://go.dev/play/p/TPKAb6ILdHk)]
+
+### HasKey
+
+Returns whether the given key exists.
+
+```go
+exists := lo.HasKey(map[string]int{"foo": 1, "bar": 2}, "foo")
+// true
+
+exists := lo.HasKey(map[string]int{"foo": 1, "bar": 2}, "baz")
+// false
+```
+
+[[play](https://go.dev/play/p/aVwubIvECqS)]
+
+### Values
+
+Creates an array of the map values.
+
+Use the UniqValues variant to deduplicate common values.
+
+```go
+values := lo.Values(map[string]int{"foo": 1, "bar": 2})
+// []int{1, 2}
+
+values := lo.Values(map[string]int{"foo": 1, "bar": 2}, map[string]int{"baz": 3})
+// []int{1, 2, 3}
+
+values := lo.Values(map[string]int{"foo": 1, "bar": 2}, map[string]int{"bar": 2})
+// []int{1, 2, 2}
+```
+
+[[play](https://go.dev/play/p/nnRTQkzQfF6)]
+
+### UniqValues
+
+Creates an array of unique map values.
+
+```go
+values := lo.UniqValues(map[string]int{"foo": 1, "bar": 2})
+// []int{1, 2}
+
+values := lo.UniqValues(map[string]int{"foo": 1, "bar": 2}, map[string]int{"baz": 3})
+// []int{1, 2, 3}
+
+values := lo.UniqValues(map[string]int{"foo": 1, "bar": 2}, map[string]int{"bar": 2})
+// []int{1, 2}
+```
+
+[[play](https://go.dev/play/p/nf6bXMh7rM3)]
+
+### ValueOr
+
+Returns the value of the given key or the fallback value if the key is not present.
+
+```go
+value := lo.ValueOr(map[string]int{"foo": 1, "bar": 2}, "foo", 42)
+// 1
+
+value := lo.ValueOr(map[string]int{"foo": 1, "bar": 2}, "baz", 42)
+// 42
+```
+
+[[play](https://go.dev/play/p/bAq9mHErB4V)]
+
+### PickBy
+
+Returns same map type filtered by given predicate.
+
+```go
+m := lo.PickBy(map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(key string, value int) bool {
+ return value%2 == 1
+})
+// map[string]int{"foo": 1, "baz": 3}
+```
+
+[[play](https://go.dev/play/p/kdg8GR_QMmf)]
+
+### PickByKeys
+
+Returns same map type filtered by given keys.
+
+```go
+m := lo.PickByKeys(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"})
+// map[string]int{"foo": 1, "baz": 3}
+```
+
+[[play](https://go.dev/play/p/R1imbuci9qU)]
+
+### PickByValues
+
+Returns same map type filtered by given values.
+
+```go
+m := lo.PickByValues(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []int{1, 3})
+// map[string]int{"foo": 1, "baz": 3}
+```
+
+[[play](https://go.dev/play/p/1zdzSvbfsJc)]
+
+### OmitBy
+
+Returns same map type filtered by given predicate.
+
+```go
+m := lo.OmitBy(map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(key string, value int) bool {
+ return value%2 == 1
+})
+// map[string]int{"bar": 2}
+```
+
+[[play](https://go.dev/play/p/EtBsR43bdsd)]
+
+### OmitByKeys
+
+Returns same map type filtered by given keys.
+
+```go
+m := lo.OmitByKeys(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"})
+// map[string]int{"bar": 2}
+```
+
+[[play](https://go.dev/play/p/t1QjCrs-ysk)]
+
+### OmitByValues
+
+Returns same map type filtered by given values.
+
+```go
+m := lo.OmitByValues(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []int{1, 3})
+// map[string]int{"bar": 2}
+```
+
+[[play](https://go.dev/play/p/9UYZi-hrs8j)]
+
+### Entries (alias: ToPairs)
+
+Transforms a map into array of key/value pairs.
+
+```go
+entries := lo.Entries(map[string]int{"foo": 1, "bar": 2})
+// []lo.Entry[string, int]{
+// {
+// Key: "foo",
+// Value: 1,
+// },
+// {
+// Key: "bar",
+// Value: 2,
+// },
+// }
+```
+
+[[play](https://go.dev/play/p/3Dhgx46gawJ)]
+
+### FromEntries (alias: FromPairs)
+
+Transforms an array of key/value pairs into a map.
+
+```go
+m := lo.FromEntries([]lo.Entry[string, int]{
+ {
+ Key: "foo",
+ Value: 1,
+ },
+ {
+ Key: "bar",
+ Value: 2,
+ },
+})
+// map[string]int{"foo": 1, "bar": 2}
+```
+
+[[play](https://go.dev/play/p/oIr5KHFGCEN)]
+
+### Invert
+
+Creates a map composed of the inverted keys and values. If map contains duplicate values, subsequent values overwrite property assignments of previous values.
+
+```go
+m1 := lo.Invert(map[string]int{"a": 1, "b": 2})
+// map[int]string{1: "a", 2: "b"}
+
+m2 := lo.Invert(map[string]int{"a": 1, "b": 2, "c": 1})
+// map[int]string{1: "c", 2: "b"}
+```
+
+[[play](https://go.dev/play/p/rFQ4rak6iA1)]
+
+### Assign
+
+Merges multiple maps from left to right.
+
+```go
+mergedMaps := lo.Assign(
+ map[string]int{"a": 1, "b": 2},
+ map[string]int{"b": 3, "c": 4},
+)
+// map[string]int{"a": 1, "b": 3, "c": 4}
+```
+
+[[play](https://go.dev/play/p/VhwfJOyxf5o)]
+
+### ChunkEntries
+
+Splits a map into an array of elements in groups of a length equal to its size. If the map cannot be split evenly, the final chunk will contain the remaining elements.
+
+```go
+maps := lo.ChunkEntries(
+ map[string]int{
+ "a": 1,
+ "b": 2,
+ "c": 3,
+ "d": 4,
+ "e": 5,
+ },
+ 3,
+)
+// []map[string]int{
+// {"a": 1, "b": 2, "c": 3},
+// {"d": 4, "e": 5},
+// }
+```
+[[play](https://go.dev/play/p/X_YQL6mmoD-)]
+
+### MapKeys
+
+Manipulates a map keys and transforms it to a map of another type.
+
+```go
+m2 := lo.MapKeys(map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(_ int, v int) string {
+ return strconv.FormatInt(int64(v), 10)
+})
+// map[string]int{"1": 1, "2": 2, "3": 3, "4": 4}
+```
+
+[[play](https://go.dev/play/p/9_4WPIqOetJ)]
+
+### MapValues
+
+Manipulates a map values and transforms it to a map of another type.
+
+```go
+m1 := map[int]int64{1: 1, 2: 2, 3: 3}
+
+m2 := lo.MapValues(m1, func(x int64, _ int) string {
+ return strconv.FormatInt(x, 10)
+})
+// map[int]string{1: "1", 2: "2", 3: "3"}
+```
+
+[[play](https://go.dev/play/p/T_8xAfvcf0W)]
+
+### MapEntries
+
+Manipulates a map entries and transforms it to a map of another type.
+
+```go
+in := map[string]int{"foo": 1, "bar": 2}
+
+out := lo.MapEntries(in, func(k string, v int) (int, string) {
+ return v,k
+})
+// map[int]string{1: "foo", 2: "bar"}
+```
+
+[[play](https://go.dev/play/p/VuvNQzxKimT)]
+
+### MapToSlice
+
+Transforms a map into a slice based on specific iteratee.
+
+```go
+m := map[int]int64{1: 4, 2: 5, 3: 6}
+
+s := lo.MapToSlice(m, func(k int, v int64) string {
+ return fmt.Sprintf("%d_%d", k, v)
+})
+// []string{"1_4", "2_5", "3_6"}
+```
+
+[[play](https://go.dev/play/p/ZuiCZpDt6LD)]
+
+### FilterMapToSlice
+
+Transforms a map into a slice based on specific iteratee. The iteratee returns a value and a boolean. If the boolean is true, the value is added to the result slice.
+
+If the boolean is false, the value is not added to the result slice. The order of the keys in the input map is not specified and the order of the keys in the output slice is not guaranteed.
+
+```go
+kv := map[int]int64{1: 1, 2: 2, 3: 3, 4: 4}
+
+result := lo.FilterMapToSlice(kv, func(k int, v int64) (string, bool) {
+ return fmt.Sprintf("%d_%d", k, v), k%2 == 0
+})
+// []{"2_2", "4_4"}
+```
+
+### Range / RangeFrom / RangeWithSteps
+
+Creates an array of numbers (positive and/or negative) progressing from start up to, but not including end.
+
+```go
+result := lo.Range(4)
+// [0, 1, 2, 3]
+
+result := lo.Range(-4)
+// [0, -1, -2, -3]
+
+result := lo.RangeFrom(1, 5)
+// [1, 2, 3, 4, 5]
+
+result := lo.RangeFrom[float64](1.0, 5)
+// [1.0, 2.0, 3.0, 4.0, 5.0]
+
+result := lo.RangeWithSteps(0, 20, 5)
+// [0, 5, 10, 15]
+
+result := lo.RangeWithSteps[float32](-1.0, -4.0, -1.0)
+// [-1.0, -2.0, -3.0]
+
+result := lo.RangeWithSteps(1, 4, -1)
+// []
+
+result := lo.Range(0)
+// []
+```
+
+[[play](https://go.dev/play/p/0r6VimXAi9H)]
+
+### Clamp
+
+Clamps number within the inclusive lower and upper bounds.
+
+```go
+r1 := lo.Clamp(0, -10, 10)
+// 0
+
+r2 := lo.Clamp(-42, -10, 10)
+// -10
+
+r3 := lo.Clamp(42, -10, 10)
+// 10
+```
+
+[[play](https://go.dev/play/p/RU4lJNC2hlI)]
+
+### Sum
+
+Sums the values in a collection.
+
+If collection is empty 0 is returned.
+
+```go
+list := []int{1, 2, 3, 4, 5}
+sum := lo.Sum(list)
+// 15
+```
+
+[[play](https://go.dev/play/p/upfeJVqs4Bt)]
+
+### SumBy
+
+Summarizes the values in a collection using the given return value from the iteration function.
+
+If collection is empty 0 is returned.
+
+```go
+strings := []string{"foo", "bar"}
+sum := lo.SumBy(strings, func(item string) int {
+ return len(item)
+})
+// 6
+```
+
+### Product
+
+Calculates the product of the values in a collection.
+
+If collection is empty 0 is returned.
+
+```go
+list := []int{1, 2, 3, 4, 5}
+product := lo.Product(list)
+// 120
+```
+
+[[play](https://go.dev/play/p/2_kjM_smtAH)]
+
+### ProductBy
+
+Calculates the product of the values in a collection using the given return value from the iteration function.
+
+If collection is empty 0 is returned.
+
+```go
+strings := []string{"foo", "bar"}
+product := lo.ProductBy(strings, func(item string) int {
+ return len(item)
+})
+// 9
+```
+
+[[play](https://go.dev/play/p/wadzrWr9Aer)]
+
+### Mean
+
+Calculates the mean of a collection of numbers.
+
+If collection is empty 0 is returned.
+
+```go
+mean := lo.Mean([]int{2, 3, 4, 5})
+// 3
+
+mean := lo.Mean([]float64{2, 3, 4, 5})
+// 3.5
+
+mean := lo.Mean([]float64{})
+// 0
+```
+
+### MeanBy
+
+Calculates the mean of a collection of numbers using the given return value from the iteration function.
+
+If collection is empty 0 is returned.
+
+```go
+list := []string{"aa", "bbb", "cccc", "ddddd"}
+mapper := func(item string) float64 {
+ return float64(len(item))
+}
+
+mean := lo.MeanBy(list, mapper)
+// 3.5
+
+mean := lo.MeanBy([]float64{}, mapper)
+// 0
+```
+
+### RandomString
+
+Returns a random string of the specified length and made of the specified charset.
+
+```go
+str := lo.RandomString(5, lo.LettersCharset)
+// example: "eIGbt"
+```
+
+[[play](https://go.dev/play/p/rRseOQVVum4)]
+
+### Substring
+
+Return part of a string.
+
+```go
+sub := lo.Substring("hello", 2, 3)
+// "llo"
+
+sub := lo.Substring("hello", -4, 3)
+// "ell"
+
+sub := lo.Substring("hello", -2, math.MaxUint)
+// "lo"
+```
+
+[[play](https://go.dev/play/p/TQlxQi82Lu1)]
+
+### ChunkString
+
+Returns an array of strings split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
+
+```go
+lo.ChunkString("123456", 2)
+// []string{"12", "34", "56"}
+
+lo.ChunkString("1234567", 2)
+// []string{"12", "34", "56", "7"}
+
+lo.ChunkString("", 2)
+// []string{""}
+
+lo.ChunkString("1", 2)
+// []string{"1"}
+```
+
+[[play](https://go.dev/play/p/__FLTuJVz54)]
+
+### RuneLength
+
+An alias to utf8.RuneCountInString which returns the number of runes in string.
+
+```go
+sub := lo.RuneLength("hellô")
+// 5
+
+sub := len("hellô")
+// 6
+```
+
+[[play](https://go.dev/play/p/tuhgW_lWY8l)]
+
+### PascalCase
+
+Converts string to pascal case.
+
+```go
+str := lo.PascalCase("hello_world")
+// HelloWorld
+```
+
+[[play](https://go.dev/play/p/iZkdeLP9oiB)]
+
+### CamelCase
+
+Converts string to camel case.
+
+```go
+str := lo.CamelCase("hello_world")
+// helloWorld
+```
+
+[[play](https://go.dev/play/p/dtyFB58MBRp)]
+
+### KebabCase
+
+Converts string to kebab case.
+
+```go
+str := lo.KebabCase("helloWorld")
+// hello-world
+```
+
+[[play](https://go.dev/play/p/2YTuPafwECA)]
+
+### SnakeCase
+
+Converts string to snake case.
+
+```go
+str := lo.SnakeCase("HelloWorld")
+// hello_world
+```
+
+[[play](https://go.dev/play/p/QVKJG9nOnDg)]
+
+### Words
+
+Splits string into an array of its words.
+
+```go
+str := lo.Words("helloWorld")
+// []string{"hello", "world"}
+```
+
+[[play](https://go.dev/play/p/2P4zhqqq61g)]
+
+### Capitalize
+
+Converts the first character of string to upper case and the remaining to lower case.
+
+```go
+str := lo.Capitalize("heLLO")
+// Hello
+```
+
+### Ellipsis
+
+Trims and truncates a string to a specified length **in bytes** and appends an ellipsis if truncated. If the string contains non-ASCII characters (which may occupy multiple bytes in UTF-8), truncating by byte length may split a character in the middle, potentially resulting in garbled output.
+
+```go
+str := lo.Ellipsis(" Lorem Ipsum ", 5)
+// Lo...
+
+str := lo.Ellipsis("Lorem Ipsum", 100)
+// Lorem Ipsum
+
+str := lo.Ellipsis("Lorem Ipsum", 3)
+// ...
+```
+
+### T2 -> T9
+
+Creates a tuple from a list of values.
+
+```go
+tuple1 := lo.T2("x", 1)
+// Tuple2[string, int]{A: "x", B: 1}
+
+func example() (string, int) { return "y", 2 }
+tuple2 := lo.T2(example())
+// Tuple2[string, int]{A: "y", B: 2}
+```
+
+[[play](https://go.dev/play/p/IllL3ZO4BQm)]
+
+### Unpack2 -> Unpack9
+
+Returns values contained in tuple.
+
+```go
+r1, r2 := lo.Unpack2(lo.Tuple2[string, int]{"a", 1})
+// "a", 1
+```
+
+Unpack is also available as a method of TupleX.
+
+```go
+tuple2 := lo.T2("a", 1)
+a, b := tuple2.Unpack()
+// "a", 1
+```
+
+[[play](https://go.dev/play/p/xVP_k0kJ96W)]
+
+### Zip2 -> Zip9
+
+Zip creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+
+When collections have different size, the Tuple attributes are filled with zero value.
+
+```go
+tuples := lo.Zip2([]string{"a", "b"}, []int{1, 2})
+// []Tuple2[string, int]{{A: "a", B: 1}, {A: "b", B: 2}}
+```
+
+[[play](https://go.dev/play/p/jujaA6GaJTp)]
+
+### ZipBy2 -> ZipBy9
+
+ZipBy creates a slice of transformed elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+
+When collections have different size, the Tuple attributes are filled with zero value.
+
+```go
+items := lo.ZipBy2([]string{"a", "b"}, []int{1, 2}, func(a string, b int) string {
+ return fmt.Sprintf("%s-%d", a, b)
+})
+// []string{"a-1", "b-2"}
+```
+
+### Unzip2 -> Unzip9
+
+Unzip accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
+
+```go
+a, b := lo.Unzip2([]Tuple2[string, int]{{A: "a", B: 1}, {A: "b", B: 2}})
+// []string{"a", "b"}
+// []int{1, 2}
+```
+
+[[play](https://go.dev/play/p/ciHugugvaAW)]
+
+### UnzipBy2 -> UnzipBy9
+
+UnzipBy2 iterates over a collection and creates an array regrouping the elements to their pre-zip configuration.
+
+```go
+a, b := lo.UnzipBy2([]string{"hello", "john", "doe"}, func(str string) (string, int) {
+ return str, len(str)
+})
+// []string{"hello", "john", "doe"}
+// []int{5, 4, 3}
+```
+
+### CrossJoin2 -> CrossJoin9
+
+Combines every items from one list with every items from others. It is the cartesian product of lists received as arguments. It returns an empty list if a list is empty.
+
+```go
+result := lo.CrossJoin2([]string{"hello", "john", "doe"}, []int{1, 2})
+// lo.Tuple2{"hello", 1}
+// lo.Tuple2{"hello", 2}
+// lo.Tuple2{"john", 1}
+// lo.Tuple2{"john", 2}
+// lo.Tuple2{"doe", 1}
+// lo.Tuple2{"doe", 2}
+```
+
+### CrossJoinBy2 -> CrossJoinBy9
+
+Combines every items from one list with every items from others. It is the cartesian product of lists received as arguments. The project function is used to create the output values. It returns an empty list if a list is empty.
+
+```go
+result := lo.CrossJoinBy2([]string{"hello", "john", "doe"}, []int{1, 2}, func(a A, b B) string {
+ return fmt.Sprintf("%s - %d", a, b)
+})
+// "hello - 1"
+// "hello - 2"
+// "john - 1"
+// "john - 2"
+// "doe - 1"
+// "doe - 2"
+```
+
+### Duration
+
+Returns the time taken to execute a function.
+
+```go
+duration := lo.Duration(func() {
+ // very long job
+})
+// 3s
+```
+
+### Duration0 -> Duration10
+
+Returns the time taken to execute a function.
+
+```go
+duration := lo.Duration0(func() {
+ // very long job
+})
+// 3s
+
+err, duration := lo.Duration1(func() error {
+ // very long job
+ return fmt.Errorf("an error")
+})
+// an error
+// 3s
+
+str, nbr, err, duration := lo.Duration3(func() (string, int, error) {
+ // very long job
+ return "hello", 42, nil
+})
+// hello
+// 42
+// nil
+// 3s
+```
+
+### ChannelDispatcher
+
+Distributes messages from input channels into N child channels. Close events are propagated to children.
+
+Underlying channels can have a fixed buffer capacity or be unbuffered when cap is 0.
+
+```go
+ch := make(chan int, 42)
+for i := 0; i <= 10; i++ {
+ ch <- i
+}
+
+children := lo.ChannelDispatcher(ch, 5, 10, DispatchingStrategyRoundRobin[int])
+// []<-chan int{...}
+
+consumer := func(c <-chan int) {
+ for {
+ msg, ok := <-c
+ if !ok {
+ println("closed")
+
+ break
+ }
+
+ println(msg)
+ }
+}
+
+for i := range children {
+ go consumer(children[i])
+}
+```
+
+Many distributions strategies are available:
+
+- [lo.DispatchingStrategyRoundRobin](./channel.go): Distributes messages in a rotating sequential manner.
+- [lo.DispatchingStrategyRandom](./channel.go): Distributes messages in a random manner.
+- [lo.DispatchingStrategyWeightedRandom](./channel.go): Distributes messages in a weighted manner.
+- [lo.DispatchingStrategyFirst](./channel.go): Distributes messages in the first non-full channel.
+- [lo.DispatchingStrategyLeast](./channel.go): Distributes messages in the emptiest channel.
+- [lo.DispatchingStrategyMost](./channel.go): Distributes to the fullest channel.
+
+Some strategies bring fallback, in order to favor non-blocking behaviors. See implementations.
+
+For custom strategies, just implement the `lo.DispatchingStrategy` prototype:
+
+```go
+type DispatchingStrategy[T any] func(message T, messageIndex uint64, channels []<-chan T) int
+```
+
+Eg:
+
+```go
+type Message struct {
+ TenantID uuid.UUID
+}
+
+func hash(id uuid.UUID) int {
+ h := fnv.New32a()
+ h.Write([]byte(id.String()))
+ return int(h.Sum32())
+}
+
+// Routes messages per TenantID.
+customStrategy := func(message string, messageIndex uint64, channels []<-chan string) int {
+ destination := hash(message) % len(channels)
+
+ // check if channel is full
+ if len(channels[destination]) < cap(channels[destination]) {
+ return destination
+ }
+
+ // fallback when child channel is full
+ return utils.DispatchingStrategyRoundRobin(message, uint64(destination), channels)
+}
+
+children := lo.ChannelDispatcher(ch, 5, 10, customStrategy)
+...
+```
+
+### SliceToChannel
+
+Returns a read-only channels of collection elements. Channel is closed after last element. Channel capacity can be customized.
+
+```go
+list := []int{1, 2, 3, 4, 5}
+
+for v := range lo.SliceToChannel(2, list) {
+ println(v)
+}
+// prints 1, then 2, then 3, then 4, then 5
+```
+
+### ChannelToSlice
+
+Returns a slice built from channels items. Blocks until channel closes.
+
+```go
+list := []int{1, 2, 3, 4, 5}
+ch := lo.SliceToChannel(2, list)
+
+items := ChannelToSlice(ch)
+// []int{1, 2, 3, 4, 5}
+```
+
+### Generator
+
+Implements the generator design pattern. Channel is closed after last element. Channel capacity can be customized.
+
+```go
+generator := func(yield func(int)) {
+ yield(1)
+ yield(2)
+ yield(3)
+}
+
+for v := range lo.Generator(2, generator) {
+ println(v)
+}
+// prints 1, then 2, then 3
+```
+
+### Buffer
+
+Creates a slice of n elements from a channel. Returns the slice, the slice length, the read time and the channel status (opened/closed).
+
+```go
+ch := lo.SliceToChannel(2, []int{1, 2, 3, 4, 5})
+
+items1, length1, duration1, ok1 := lo.Buffer(ch, 3)
+// []int{1, 2, 3}, 3, 0s, true
+items2, length2, duration2, ok2 := lo.Buffer(ch, 3)
+// []int{4, 5}, 2, 0s, false
+```
+
+Example: RabbitMQ consumer 👇
+
+```go
+ch := readFromQueue()
+
+for {
+ // read 1k items
+ items, length, _, ok := lo.Buffer(ch, 1000)
+
+ // do batching stuff
+
+ if !ok {
+ break
+ }
+}
+```
+
+### BufferWithContext
+
+Creates a slice of n elements from a channel, with timeout. Returns the slice, the slice length, the read time and the channel status (opened/closed).
+
+```go
+ctx, cancel := context.WithCancel(context.TODO())
+go func() {
+ ch <- 0
+ time.Sleep(10*time.Millisecond)
+ ch <- 1
+ time.Sleep(10*time.Millisecond)
+ ch <- 2
+ time.Sleep(10*time.Millisecond)
+ ch <- 3
+ time.Sleep(10*time.Millisecond)
+ ch <- 4
+ time.Sleep(10*time.Millisecond)
+ cancel()
+}()
+
+items1, length1, duration1, ok1 := lo.BufferWithContext(ctx, ch, 3)
+// []int{0, 1, 2}, 3, 20ms, true
+items2, length2, duration2, ok2 := lo.BufferWithContext(ctx, ch, 3)
+// []int{3, 4}, 2, 30ms, false
+```
+
+### BufferWithTimeout
+
+Creates a slice of n elements from a channel, with timeout. Returns the slice, the slice length, the read time and the channel status (opened/closed).
+
+```go
+generator := func(yield func(int)) {
+ for i := 0; i < 5; i++ {
+ yield(i)
+ time.Sleep(35*time.Millisecond)
+ }
+}
+
+ch := lo.Generator(0, generator)
+
+items1, length1, duration1, ok1 := lo.BufferWithTimeout(ch, 3, 100*time.Millisecond)
+// []int{1, 2}, 2, 100ms, true
+items2, length2, duration2, ok2 := lo.BufferWithTimeout(ch, 3, 100*time.Millisecond)
+// []int{3, 4, 5}, 3, 75ms, true
+items3, length3, duration2, ok3 := lo.BufferWithTimeout(ch, 3, 100*time.Millisecond)
+// []int{}, 0, 10ms, false
+```
+
+Example: RabbitMQ consumer 👇
+
+```go
+ch := readFromQueue()
+
+for {
+ // read 1k items
+ // wait up to 1 second
+ items, length, _, ok := lo.BufferWithTimeout(ch, 1000, 1*time.Second)
+
+ // do batching stuff
+
+ if !ok {
+ break
+ }
+}
+```
+
+Example: Multithreaded RabbitMQ consumer 👇
+
+```go
+ch := readFromQueue()
+
+// 5 workers
+// prefetch 1k messages per worker
+children := lo.ChannelDispatcher(ch, 5, 1000, lo.DispatchingStrategyFirst[int])
+
+consumer := func(c <-chan int) {
+ for {
+ // read 1k items
+ // wait up to 1 second
+ items, length, _, ok := lo.BufferWithTimeout(ch, 1000, 1*time.Second)
+
+ // do batching stuff
+
+ if !ok {
+ break
+ }
+ }
+}
+
+for i := range children {
+ go consumer(children[i])
+}
+```
+
+### FanIn
+
+Merge messages from multiple input channels into a single buffered channel. Output messages has no priority. When all upstream channels reach EOF, downstream channel closes.
+
+```go
+stream1 := make(chan int, 42)
+stream2 := make(chan int, 42)
+stream3 := make(chan int, 42)
+
+all := lo.FanIn(100, stream1, stream2, stream3)
+// <-chan int
+```
+
+### FanOut
+
+Broadcasts all the upstream messages to multiple downstream channels. When upstream channel reach EOF, downstream channels close. If any downstream channels is full, broadcasting is paused.
+
+```go
+stream := make(chan int, 42)
+
+all := lo.FanOut(5, 100, stream)
+// [5]<-chan int
+```
+
+### Contains
+
+Returns true if an element is present in a collection.
+
+```go
+present := lo.Contains([]int{0, 1, 2, 3, 4, 5}, 5)
+// true
+```
+
+### ContainsBy
+
+Returns true if the predicate function returns `true`.
+
+```go
+present := lo.ContainsBy([]int{0, 1, 2, 3, 4, 5}, func(x int) bool {
+ return x == 3
+})
+// true
+```
+
+### Every
+
+Returns true if all elements of a subset are contained into a collection or if the subset is empty.
+
+```go
+ok := lo.Every([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
+// true
+
+ok := lo.Every([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
+// false
+```
+
+### EveryBy
+
+Returns true if the predicate returns true for all elements in the collection or if the collection is empty.
+
+```go
+b := EveryBy([]int{1, 2, 3, 4}, func(x int) bool {
+ return x < 5
+})
+// true
+```
+
+### Some
+
+Returns true if at least 1 element of a subset is contained into a collection.
+If the subset is empty Some returns false.
+
+```go
+ok := lo.Some([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
+// true
+
+ok := lo.Some([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
+// false
+```
+
+### SomeBy
+
+Returns true if the predicate returns true for any of the elements in the collection.
+If the collection is empty SomeBy returns false.
+
+```go
+b := SomeBy([]int{1, 2, 3, 4}, func(x int) bool {
+ return x < 3
+})
+// true
+```
+
+### None
+
+Returns true if no element of a subset are contained into a collection or if the subset is empty.
+
+```go
+b := None([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
+// false
+b := None([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
+// true
+```
+
+### NoneBy
+
+Returns true if the predicate returns true for none of the elements in the collection or if the collection is empty.
+
+```go
+b := NoneBy([]int{1, 2, 3, 4}, func(x int) bool {
+ return x < 0
+})
+// true
+```
+
+### Intersect
+
+Returns the intersection between two collections.
+
+```go
+result1 := lo.Intersect([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
+// []int{0, 2}
+
+result2 := lo.Intersect([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
+// []int{0}
+
+result3 := lo.Intersect([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
+// []int{}
+```
+
+### Difference
+
+Returns the difference between two collections.
+
+- The first value is the collection of element absent of list2.
+- The second value is the collection of element absent of list1.
+
+```go
+left, right := lo.Difference([]int{0, 1, 2, 3, 4, 5}, []int{0, 2, 6})
+// []int{1, 3, 4, 5}, []int{6}
+
+left, right := lo.Difference([]int{0, 1, 2, 3, 4, 5}, []int{0, 1, 2, 3, 4, 5})
+// []int{}, []int{}
+```
+
+### Union
+
+Returns all distinct elements from given collections. Result will not change the order of elements relatively.
+
+```go
+union := lo.Union([]int{0, 1, 2, 3, 4, 5}, []int{0, 2}, []int{0, 10})
+// []int{0, 1, 2, 3, 4, 5, 10}
+```
+
+### Without
+
+Returns slice excluding all given values.
+
+```go
+subset := lo.Without([]int{0, 2, 10}, 2)
+// []int{0, 10}
+
+subset := lo.Without([]int{0, 2, 10}, 0, 1, 2, 3, 4, 5)
+// []int{10}
+```
+
+### WithoutBy
+
+Filters a slice by excluding elements whose extracted keys match any in the exclude list.
+
+It returns a new slice containing only the elements whose keys are not in the exclude list.
+
+
+```go
+type struct User {
+ ID int
+ Name string
+}
+
+// original users
+users := []User{
+ {ID: 1, Name: "Alice"},
+ {ID: 2, Name: "Bob"},
+ {ID: 3, Name: "Charlie"},
+}
+
+// extract function to get the user ID
+getID := func(user User) int {
+ return user.ID
+}
+
+// exclude users with IDs 2 and 3
+excludedIDs := []int{2, 3}
+
+// filtering users
+filteredUsers := lo.WithoutBy(users, getID, excludedIDs...)
+// []User[{ID: 1, Name: "Alice"}]
+```
+
+### WithoutEmpty
+
+Returns slice excluding zero values.
+
+```go
+subset := lo.WithoutEmpty([]int{0, 2, 10})
+// []int{2, 10}
+```
+
+### WithoutNth
+
+Returns slice excluding nth value.
+
+```go
+subset := lo.WithoutNth([]int{-2, -1, 0, 1, 2}, 3, -42, 1)
+// []int{-2, 0, 2}
+```
+
+### ElementsMatch
+
+Returns true if lists contain the same set of elements (including empty set).
+
+If there are duplicate elements, the number of appearances of each of them in both lists should match.
+
+The order of elements is not checked.
+
+```go
+b := lo.ElementsMatch([]int{1, 1, 2}, []int{2, 1, 1})
+// true
+```
+
+### ElementsMatchBy
+
+Returns true if lists contain the same set of elements' keys (including empty set).
+
+If there are duplicate keys, the number of appearances of each of them in both lists should match.
+
+The order of elements is not checked.
+
+```go
+b := lo.ElementsMatchBy(
+ []someType{a, b},
+ []someType{b, a},
+ func(item someType) string { return item.ID() },
+)
+// true
+```
+
+### IndexOf
+
+Returns the index at which the first occurrence of a value is found in an array or return -1 if the value cannot be found.
+
+```go
+found := lo.IndexOf([]int{0, 1, 2, 1, 2, 3}, 2)
+// 2
+
+notFound := lo.IndexOf([]int{0, 1, 2, 1, 2, 3}, 6)
+// -1
+```
+
+### LastIndexOf
+
+Returns the index at which the last occurrence of a value is found in an array or return -1 if the value cannot be found.
+
+```go
+found := lo.LastIndexOf([]int{0, 1, 2, 1, 2, 3}, 2)
+// 4
+
+notFound := lo.LastIndexOf([]int{0, 1, 2, 1, 2, 3}, 6)
+// -1
+```
+
+### Find
+
+Search an element in a slice based on a predicate. It returns element and true if element was found.
+
+```go
+str, ok := lo.Find([]string{"a", "b", "c", "d"}, func(i string) bool {
+ return i == "b"
+})
+// "b", true
+
+str, ok := lo.Find([]string{"foobar"}, func(i string) bool {
+ return i == "b"
+})
+// "", false
+```
+
+### FindIndexOf
+
+FindIndexOf searches an element in a slice based on a predicate and returns the index and true. It returns -1 and false if the element is not found.
+
+```go
+str, index, ok := lo.FindIndexOf([]string{"a", "b", "a", "b"}, func(i string) bool {
+ return i == "b"
+})
+// "b", 1, true
+
+str, index, ok := lo.FindIndexOf([]string{"foobar"}, func(i string) bool {
+ return i == "b"
+})
+// "", -1, false
+```
+
+### FindLastIndexOf
+
+FindLastIndexOf searches an element in a slice based on a predicate and returns the index and true. It returns -1 and false if the element is not found.
+
+```go
+str, index, ok := lo.FindLastIndexOf([]string{"a", "b", "a", "b"}, func(i string) bool {
+ return i == "b"
+})
+// "b", 4, true
+
+str, index, ok := lo.FindLastIndexOf([]string{"foobar"}, func(i string) bool {
+ return i == "b"
+})
+// "", -1, false
+```
+
+### FindOrElse
+
+Search an element in a slice based on a predicate. It returns the element if found or a given fallback value otherwise.
+
+```go
+str := lo.FindOrElse([]string{"a", "b", "c", "d"}, "x", func(i string) bool {
+ return i == "b"
+})
+// "b"
+
+str := lo.FindOrElse([]string{"foobar"}, "x", func(i string) bool {
+ return i == "b"
+})
+// "x"
+```
+
+### FindKey
+
+Returns the key of the first value matching.
+
+```go
+result1, ok1 := lo.FindKey(map[string]int{"foo": 1, "bar": 2, "baz": 3}, 2)
+// "bar", true
+
+result2, ok2 := lo.FindKey(map[string]int{"foo": 1, "bar": 2, "baz": 3}, 42)
+// "", false
+
+type test struct {
+ foobar string
+}
+result3, ok3 := lo.FindKey(map[string]test{"foo": test{"foo"}, "bar": test{"bar"}, "baz": test{"baz"}}, test{"foo"})
+// "foo", true
+```
+
+### FindKeyBy
+
+Returns the key of the first element predicate returns truthy for.
+
+```go
+result1, ok1 := lo.FindKeyBy(map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(k string, v int) bool {
+ return k == "foo"
+})
+// "foo", true
+
+result2, ok2 := lo.FindKeyBy(map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(k string, v int) bool {
+ return false
+})
+// "", false
+```
+
+### FindUniques
+
+Returns a slice with all the unique elements of the collection. The order of result values is determined by the order they occur in the array.
+
+```go
+uniqueValues := lo.FindUniques([]int{1, 2, 2, 1, 2, 3})
+// []int{3}
+```
+
+### FindUniquesBy
+
+Returns a slice with all the unique elements of the collection. The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed.
+
+```go
+uniqueValues := lo.FindUniquesBy([]int{3, 4, 5, 6, 7}, func(i int) int {
+ return i%3
+})
+// []int{5}
+```
+
+### FindDuplicates
+
+Returns a slice with the first occurrence of each duplicated elements of the collection. The order of result values is determined by the order they occur in the array.
+
+```go
+duplicatedValues := lo.FindDuplicates([]int{1, 2, 2, 1, 2, 3})
+// []int{1, 2}
+```
+
+### FindDuplicatesBy
+
+Returns a slice with the first occurrence of each duplicated elements of the collection. The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed.
+
+```go
+duplicatedValues := lo.FindDuplicatesBy([]int{3, 4, 5, 6, 7}, func(i int) int {
+ return i%3
+})
+// []int{3, 4}
+```
+
+### Min
+
+Search the minimum value of a collection.
+
+Returns zero value when the collection is empty.
+
+```go
+min := lo.Min([]int{1, 2, 3})
+// 1
+
+min := lo.Min([]int{})
+// 0
+
+min := lo.Min([]time.Duration{time.Second, time.Hour})
+// 1s
+```
+
+### MinIndex
+
+Search the minimum value of a collection and the index of the minimum value.
+
+Returns (zero value, -1) when the collection is empty.
+
+```go
+min, index := lo.MinIndex([]int{1, 2, 3})
+// 1, 0
+
+min, index := lo.MinIndex([]int{})
+// 0, -1
+
+min, index := lo.MinIndex([]time.Duration{time.Second, time.Hour})
+// 1s, 0
+```
+
+### MinBy
+
+Search the minimum value of a collection using the given comparison function.
+
+If several values of the collection are equal to the smallest value, returns the first such value.
+
+Returns zero value when the collection is empty.
+
+```go
+min := lo.MinBy([]string{"s1", "string2", "s3"}, func(item string, min string) bool {
+ return len(item) < len(min)
+})
+// "s1"
+
+min := lo.MinBy([]string{}, func(item string, min string) bool {
+ return len(item) < len(min)
+})
+// ""
+```
+
+### MinIndexBy
+
+Search the minimum value of a collection using the given comparison function and the index of the minimum value.
+
+If several values of the collection are equal to the smallest value, returns the first such value.
+
+Returns (zero value, -1) when the collection is empty.
+
+```go
+min, index := lo.MinIndexBy([]string{"s1", "string2", "s3"}, func(item string, min string) bool {
+ return len(item) < len(min)
+})
+// "s1", 0
+
+min, index := lo.MinIndexBy([]string{}, func(item string, min string) bool {
+ return len(item) < len(min)
+})
+// "", -1
+```
+
+### Earliest
+
+Search the minimum time.Time of a collection.
+
+Returns zero value when the collection is empty.
+
+```go
+earliest := lo.Earliest(time.Now(), time.Time{})
+// 0001-01-01 00:00:00 +0000 UTC
+```
+
+### EarliestBy
+
+Search the minimum time.Time of a collection using the given iteratee function.
+
+Returns zero value when the collection is empty.
+
+```go
+type foo struct {
+ bar time.Time
+}
+
+earliest := lo.EarliestBy([]foo{{time.Now()}, {}}, func(i foo) time.Time {
+ return i.bar
+})
+// {bar:{2023-04-01 01:02:03 +0000 UTC}}
+```
+
+### Max
+
+Search the maximum value of a collection.
+
+Returns zero value when the collection is empty.
+
+```go
+max := lo.Max([]int{1, 2, 3})
+// 3
+
+max := lo.Max([]int{})
+// 0
+
+max := lo.Max([]time.Duration{time.Second, time.Hour})
+// 1h
+```
+
+### MaxIndex
+
+Search the maximum value of a collection and the index of the maximum value.
+
+Returns (zero value, -1) when the collection is empty.
+
+```go
+max, index := lo.MaxIndex([]int{1, 2, 3})
+// 3, 2
+
+max, index := lo.MaxIndex([]int{})
+// 0, -1
+
+max, index := lo.MaxIndex([]time.Duration{time.Second, time.Hour})
+// 1h, 1
+```
+
+### MaxBy
+
+Search the maximum value of a collection using the given comparison function.
+
+If several values of the collection are equal to the greatest value, returns the first such value.
+
+Returns zero value when the collection is empty.
+
+```go
+max := lo.MaxBy([]string{"string1", "s2", "string3"}, func(item string, max string) bool {
+ return len(item) > len(max)
+})
+// "string1"
+
+max := lo.MaxBy([]string{}, func(item string, max string) bool {
+ return len(item) > len(max)
+})
+// ""
+```
+
+### MaxIndexBy
+
+Search the maximum value of a collection using the given comparison function and the index of the maximum value.
+
+If several values of the collection are equal to the greatest value, returns the first such value.
+
+Returns (zero value, -1) when the collection is empty.
+
+```go
+max, index := lo.MaxIndexBy([]string{"string1", "s2", "string3"}, func(item string, max string) bool {
+ return len(item) > len(max)
+})
+// "string1", 0
+
+max, index := lo.MaxIndexBy([]string{}, func(item string, max string) bool {
+ return len(item) > len(max)
+})
+// "", -1
+```
+
+### Latest
+
+Search the maximum time.Time of a collection.
+
+Returns zero value when the collection is empty.
+
+```go
+latest := lo.Latest(time.Now(), time.Time{})
+// 2023-04-01 01:02:03 +0000 UTC
+```
+
+### LatestBy
+
+Search the maximum time.Time of a collection using the given iteratee function.
+
+Returns zero value when the collection is empty.
+
+```go
+type foo struct {
+ bar time.Time
+}
+
+latest := lo.LatestBy([]foo{{time.Now()}, {}}, func(i foo) time.Time {
+ return i.bar
+})
+// {bar:{2023-04-01 01:02:03 +0000 UTC}}
+```
+
+### First
+
+Returns the first element of a collection and check for availability of the first element.
+
+```go
+first, ok := lo.First([]int{1, 2, 3})
+// 1, true
+
+first, ok := lo.First([]int{})
+// 0, false
+```
+
+### FirstOrEmpty
+
+Returns the first element of a collection or zero value if empty.
+
+```go
+first := lo.FirstOrEmpty([]int{1, 2, 3})
+// 1
+
+first := lo.FirstOrEmpty([]int{})
+// 0
+```
+
+### FirstOr
+
+Returns the first element of a collection or the fallback value if empty.
+
+```go
+first := lo.FirstOr([]int{1, 2, 3}, 245)
+// 1
+
+first := lo.FirstOr([]int{}, 31)
+// 31
+```
+
+### Last
+
+Returns the last element of a collection or error if empty.
+
+```go
+last, ok := lo.Last([]int{1, 2, 3})
+// 3
+// true
+
+last, ok := lo.Last([]int{})
+// 0
+// false
+```
+
+### LastOrEmpty
+
+Returns the last element of a collection or zero value if empty.
+
+```go
+last := lo.LastOrEmpty([]int{1, 2, 3})
+// 3
+
+last := lo.LastOrEmpty([]int{})
+// 0
+```
+
+### LastOr
+
+Returns the last element of a collection or the fallback value if empty.
+
+```go
+last := lo.LastOr([]int{1, 2, 3}, 245)
+// 3
+
+last := lo.LastOr([]int{}, 31)
+// 31
+```
+
+### Nth
+
+Returns the element at index `nth` of collection. If `nth` is negative, the nth element from the end is returned. An error is returned when nth is out of slice bounds.
+
+```go
+nth, err := lo.Nth([]int{0, 1, 2, 3}, 2)
+// 2
+
+nth, err := lo.Nth([]int{0, 1, 2, 3}, -2)
+// 2
+```
+
+### NthOr
+
+Returns the element at index `nth` of the collection. If `nth` is negative, it returns the `nth` element from the end. If `nth` is out of slice bounds, it returns the provided fallback value
+```go
+nth := lo.NthOr([]int{10, 20, 30, 40, 50}, 2, -1)
+// 30
+
+nth := lo.NthOr([]int{10, 20, 30, 40, 50}, -1, -1)
+// 50
+
+nth := lo.NthOr([]int{10, 20, 30, 40, 50}, 5, -1)
+// -1 (fallback value)
+```
+
+### NthOrEmpty
+
+Returns the element at index `nth` of the collection. If `nth` is negative, it returns the `nth` element from the end. If `nth` is out of slice bounds, it returns the zero value for the element type (e.g., 0 for integers, "" for strings, etc).
+``` go
+nth := lo.NthOrEmpty([]int{10, 20, 30, 40, 50}, 2)
+// 30
+
+nth := lo.NthOrEmpty([]int{10, 20, 30, 40, 50}, -1)
+// 50
+
+nth := lo.NthOrEmpty([]int{10, 20, 30, 40, 50}, 5)
+// 0 (zero value for int)
+
+nth := lo.NthOrEmpty([]string{"apple", "banana", "cherry"}, 2)
+// "cherry"
+
+nth := lo.NthOrEmpty([]string{"apple", "banana", "cherry"}, 5)
+// "" (zero value for string)
+```
+
+### Sample
+
+Returns a random item from collection.
+
+```go
+lo.Sample([]string{"a", "b", "c"})
+// a random string from []string{"a", "b", "c"}
+
+lo.Sample([]string{})
+// ""
+```
+
+
+
+### SampleBy
+
+Returns a random item from collection, using a given random integer generator.
+
+```go
+import "math/rand"
+
+r := rand.New(rand.NewSource(42))
+lo.SampleBy([]string{"a", "b", "c"}, r.Intn)
+// a random string from []string{"a", "b", "c"}, using a seeded random generator
+
+lo.SampleBy([]string{}, r.Intn)
+// ""
+```
+
+### Samples
+
+Returns N random unique items from collection.
+
+```go
+lo.Samples([]string{"a", "b", "c"}, 3)
+// []string{"a", "b", "c"} in random order
+```
+
+### SamplesBy
+
+Returns N random unique items from collection, using a given random integer generator.
+
+```go
+r := rand.New(rand.NewSource(42))
+lo.SamplesBy([]string{"a", "b", "c"}, 3, r.Intn)
+// []string{"a", "b", "c"} in random order, using a seeded random generator
+```
+
+### Ternary
+
+A 1 line if/else statement.
+
+
+```go
+result := lo.Ternary(true, "a", "b")
+// "a"
+
+result := lo.Ternary(false, "a", "b")
+// "b"
+```
+
+Take care to avoid dereferencing potentially nil pointers in your A/B expressions, because they are both evaluated. See TernaryF to avoid this problem.
+
+[[play](https://go.dev/play/p/t-D7WBL44h2)]
+
+### TernaryF
+
+A 1 line if/else statement whose options are functions.
+
+```go
+result := lo.TernaryF(true, func() string { return "a" }, func() string { return "b" })
+// "a"
+
+result := lo.TernaryF(false, func() string { return "a" }, func() string { return "b" })
+// "b"
+```
+
+Useful to avoid nil-pointer dereferencing in initializations, or avoid running unnecessary code
+
+```go
+var s *string
+
+someStr := TernaryF(s == nil, func() string { return uuid.New().String() }, func() string { return *s })
+// ef782193-c30c-4e2e-a7ae-f8ab5e125e02
+```
+
+[[play](https://go.dev/play/p/AO4VW20JoqM)]
+
+### If / ElseIf / Else
+
+```go
+result := lo.If(true, 1).
+ ElseIf(false, 2).
+ Else(3)
+// 1
+
+result := lo.If(false, 1).
+ ElseIf(true, 2).
+ Else(3)
+// 2
+
+result := lo.If(false, 1).
+ ElseIf(false, 2).
+ Else(3)
+// 3
+```
+
+Using callbacks:
+
+```go
+result := lo.IfF(true, func () int {
+ return 1
+ }).
+ ElseIfF(false, func () int {
+ return 2
+ }).
+ ElseF(func () int {
+ return 3
+ })
+// 1
+```
+
+Mixed:
+
+```go
+result := lo.IfF(true, func () int {
+ return 1
+ }).
+ Else(42)
+// 1
+```
+
+[[play](https://go.dev/play/p/WSw3ApMxhyW)]
+
+### Switch / Case / Default
+
+```go
+result := lo.Switch(1).
+ Case(1, "1").
+ Case(2, "2").
+ Default("3")
+// "1"
+
+result := lo.Switch(2).
+ Case(1, "1").
+ Case(2, "2").
+ Default("3")
+// "2"
+
+result := lo.Switch(42).
+ Case(1, "1").
+ Case(2, "2").
+ Default("3")
+// "3"
+```
+
+Using callbacks:
+
+```go
+result := lo.Switch(1).
+ CaseF(1, func() string {
+ return "1"
+ }).
+ CaseF(2, func() string {
+ return "2"
+ }).
+ DefaultF(func() string {
+ return "3"
+ })
+// "1"
+```
+
+Mixed:
+
+```go
+result := lo.Switch(1).
+ CaseF(1, func() string {
+ return "1"
+ }).
+ Default("42")
+// "1"
+```
+
+[[play](https://go.dev/play/p/TGbKUMAeRUd)]
+
+### IsNil
+
+Checks if a value is nil or if it's a reference type with a nil underlying value.
+
+```go
+var x int
+lo.IsNil(x)
+// false
+
+var k struct{}
+lo.IsNil(k)
+// false
+
+var i *int
+lo.IsNil(i)
+// true
+
+var ifaceWithNilValue any = (*string)(nil)
+lo.IsNil(ifaceWithNilValue)
+// true
+ifaceWithNilValue == nil
+// false
+```
+
+### IsNotNil
+
+Checks if a value is not nil or if it's not a reference type with a nil underlying value.
+
+```go
+var x int
+lo.IsNotNil(x)
+// true
+
+var k struct{}
+lo.IsNotNil(k)
+// true
+
+var i *int
+lo.IsNotNil(i)
+// false
+
+var ifaceWithNilValue any = (*string)(nil)
+lo.IsNotNil(ifaceWithNilValue)
+// false
+ifaceWithNilValue == nil
+// true
+```
+
+### ToPtr
+
+Returns a pointer copy of the value.
+
+```go
+ptr := lo.ToPtr("hello world")
+// *string{"hello world"}
+```
+
+### Nil
+
+Returns a nil pointer of type.
+
+```go
+ptr := lo.Nil[float64]()
+// nil
+```
+
+### EmptyableToPtr
+
+Returns a pointer copy of value if it's nonzero.
+Otherwise, returns nil pointer.
+
+```go
+ptr := lo.EmptyableToPtr(nil)
+// nil
+
+ptr := lo.EmptyableToPtr("")
+// nil
+
+ptr := lo.EmptyableToPtr([]int{})
+// *[]int{}
+
+ptr := lo.EmptyableToPtr("hello world")
+// *string{"hello world"}
+```
+
+### FromPtr
+
+Returns the pointer value or empty.
+
+```go
+str := "hello world"
+value := lo.FromPtr(&str)
+// "hello world"
+
+value := lo.FromPtr(nil)
+// ""
+```
+
+### FromPtrOr
+
+Returns the pointer value or the fallback value.
+
+```go
+str := "hello world"
+value := lo.FromPtrOr(&str, "empty")
+// "hello world"
+
+value := lo.FromPtrOr(nil, "empty")
+// "empty"
+```
+
+### ToSlicePtr
+
+Returns a slice of pointer copy of value.
+
+```go
+ptr := lo.ToSlicePtr([]string{"hello", "world"})
+// []*string{"hello", "world"}
+```
+
+### FromSlicePtr
+
+Returns a slice with the pointer values.
+Returns a zero value in case of a nil pointer element.
+
+```go
+str1 := "hello"
+str2 := "world"
+
+ptr := lo.FromSlicePtr[string]([]*string{&str1, &str2, nil})
+// []string{"hello", "world", ""}
+
+ptr := lo.Compact(
+ lo.FromSlicePtr[string]([]*string{&str1, &str2, nil}),
+)
+// []string{"hello", "world"}
+```
+
+### FromSlicePtrOr
+
+Returns a slice with the pointer values or the fallback value.
+
+```go
+str1 := "hello"
+str2 := "world"
+
+ptr := lo.FromSlicePtrOr([]*string{&str1, nil, &str2}, "fallback value")
+// []string{"hello", "fallback value", "world"}
+```
+
+[[play](https://go.dev/play/p/CuXGVzo9G65)]
+
+### ToAnySlice
+
+Returns a slice with all elements mapped to `any` type.
+
+```go
+elements := lo.ToAnySlice([]int{1, 5, 1})
+// []any{1, 5, 1}
+```
+
+### FromAnySlice
+
+Returns an `any` slice with all elements mapped to a type. Returns false in case of type conversion failure.
+
+```go
+elements, ok := lo.FromAnySlice([]any{"foobar", 42})
+// []string{}, false
+
+elements, ok := lo.FromAnySlice([]any{"foobar", "42"})
+// []string{"foobar", "42"}, true
+```
+
+### Empty
+
+Returns the [zero value](https://go.dev/ref/spec#The_zero_value).
+
+```go
+lo.Empty[int]()
+// 0
+lo.Empty[string]()
+// ""
+lo.Empty[bool]()
+// false
+```
+
+### IsEmpty
+
+Returns true if argument is a zero value.
+
+```go
+lo.IsEmpty(0)
+// true
+lo.IsEmpty(42)
+// false
+
+lo.IsEmpty("")
+// true
+lo.IsEmpty("foobar")
+// false
+
+type test struct {
+ foobar string
+}
+
+lo.IsEmpty(test{foobar: ""})
+// true
+lo.IsEmpty(test{foobar: "foobar"})
+// false
+```
+
+### IsNotEmpty
+
+Returns true if argument is a zero value.
+
+```go
+lo.IsNotEmpty(0)
+// false
+lo.IsNotEmpty(42)
+// true
+
+lo.IsNotEmpty("")
+// false
+lo.IsNotEmpty("foobar")
+// true
+
+type test struct {
+ foobar string
+}
+
+lo.IsNotEmpty(test{foobar: ""})
+// false
+lo.IsNotEmpty(test{foobar: "foobar"})
+// true
+```
+
+### Coalesce
+
+Returns the first non-empty arguments. Arguments must be comparable.
+
+```go
+result, ok := lo.Coalesce(0, 1, 2, 3)
+// 1 true
+
+result, ok := lo.Coalesce("")
+// "" false
+
+var nilStr *string
+str := "foobar"
+result, ok := lo.Coalesce(nil, nilStr, &str)
+// &"foobar" true
+```
+
+### CoalesceOrEmpty
+
+Returns the first non-empty arguments. Arguments must be comparable.
+
+```go
+result := lo.CoalesceOrEmpty(0, 1, 2, 3)
+// 1
+
+result := lo.CoalesceOrEmpty("")
+// ""
+
+var nilStr *string
+str := "foobar"
+result := lo.CoalesceOrEmpty(nil, nilStr, &str)
+// &"foobar"
+```
+
+### CoalesceSlice
+
+Returns the first non-zero slice.
+
+```go
+result, ok := lo.CoalesceSlice([]int{1, 2, 3}, []int{4, 5, 6})
+// [1, 2, 3]
+// true
+
+result, ok := lo.CoalesceSlice(nil, []int{})
+// []
+// true
+
+result, ok := lo.CoalesceSlice([]int(nil))
+// []
+// false
+```
+
+### CoalesceSliceOrEmpty
+
+Returns the first non-zero slice.
+
+```go
+result := lo.CoalesceSliceOrEmpty([]int{1, 2, 3}, []int{4, 5, 6})
+// [1, 2, 3]
+
+result := lo.CoalesceSliceOrEmpty(nil, []int{})
+// []
+```
+
+### CoalesceMap
+
+Returns the first non-zero map.
+
+```go
+result, ok := lo.CoalesceMap(map[string]int{"1": 1, "2": 2, "3": 3}, map[string]int{"4": 4, "5": 5, "6": 6})
+// {"1": 1, "2": 2, "3": 3}
+// true
+
+result, ok := lo.CoalesceMap(nil, map[string]int{})
+// {}
+// true
+
+result, ok := lo.CoalesceMap(map[string]int(nil))
+// {}
+// false
+```
+
+### CoalesceMapOrEmpty
+
+Returns the first non-zero map.
+
+```go
+result := lo.CoalesceMapOrEmpty(map[string]int{"1": 1, "2": 2, "3": 3}, map[string]int{"4": 4, "5": 5, "6": 6})
+// {"1": 1, "2": 2, "3": 3}
+
+result := lo.CoalesceMapOrEmpty(nil, map[string]int{})
+// {}
+```
+
+### Partial
+
+Returns new function that, when called, has its first argument set to the provided value.
+
+```go
+add := func(x, y int) int { return x + y }
+f := lo.Partial(add, 5)
+
+f(10)
+// 15
+
+f(42)
+// 47
+```
+
+### Partial2 -> Partial5
+
+Returns new function that, when called, has its first argument set to the provided value.
+
+```go
+add := func(x, y, z int) int { return x + y + z }
+f := lo.Partial2(add, 42)
+
+f(10, 5)
+// 57
+
+f(42, -4)
+// 80
+```
+
+### Attempt
+
+Invokes a function N times until it returns valid output. Returns either the caught error or nil.
+
+When the first argument is less than `1`, the function runs until a successful response is returned.
+
+```go
+iter, err := lo.Attempt(42, func(i int) error {
+ if i == 5 {
+ return nil
+ }
+
+ return fmt.Errorf("failed")
+})
+// 6
+// nil
+
+iter, err := lo.Attempt(2, func(i int) error {
+ if i == 5 {
+ return nil
+ }
+
+ return fmt.Errorf("failed")
+})
+// 2
+// error "failed"
+
+iter, err := lo.Attempt(0, func(i int) error {
+ if i < 42 {
+ return fmt.Errorf("failed")
+ }
+
+ return nil
+})
+// 43
+// nil
+```
+
+For more advanced retry strategies (delay, exponential backoff...), please take a look on [cenkalti/backoff](https://github.com/cenkalti/backoff).
+
+[[play](https://go.dev/play/p/3ggJZ2ZKcMj)]
+
+### AttemptWithDelay
+
+Invokes a function N times until it returns valid output, with a pause between each call. Returns either the caught error or nil.
+
+When the first argument is less than `1`, the function runs until a successful response is returned.
+
+```go
+iter, duration, err := lo.AttemptWithDelay(5, 2*time.Second, func(i int, duration time.Duration) error {
+ if i == 2 {
+ return nil
+ }
+
+ return fmt.Errorf("failed")
+})
+// 3
+// ~ 4 seconds
+// nil
+```
+
+For more advanced retry strategies (delay, exponential backoff...), please take a look on [cenkalti/backoff](https://github.com/cenkalti/backoff).
+
+[[play](https://go.dev/play/p/tVs6CygC7m1)]
+
+### AttemptWhile
+
+Invokes a function N times until it returns valid output. Returns either the caught error or nil, along with a bool value to determine whether the function should be invoked again. It will terminate the invoke immediately if the second return value is false.
+
+When the first argument is less than `1`, the function runs until a successful response is returned.
+
+```go
+count1, err1 := lo.AttemptWhile(5, func(i int) (error, bool) {
+ err := doMockedHTTPRequest(i)
+ if err != nil {
+ if errors.Is(err, ErrBadRequest) { // lets assume ErrBadRequest is a critical error that needs to terminate the invoke
+ return err, false // flag the second return value as false to terminate the invoke
+ }
+
+ return err, true
+ }
+
+ return nil, false
+})
+```
+
+For more advanced retry strategies (delay, exponential backoff...), please take a look on [cenkalti/backoff](https://github.com/cenkalti/backoff).
+
+[[play](https://go.dev/play/p/M2wVq24PaZM)]
+
+### AttemptWhileWithDelay
+
+Invokes a function N times until it returns valid output, with a pause between each call. Returns either the caught error or nil, along with a bool value to determine whether the function should be invoked again. It will terminate the invoke immediately if the second return value is false.
+
+When the first argument is less than `1`, the function runs until a successful response is returned.
+
+```go
+count1, time1, err1 := lo.AttemptWhileWithDelay(5, time.Millisecond, func(i int, d time.Duration) (error, bool) {
+ err := doMockedHTTPRequest(i)
+ if err != nil {
+ if errors.Is(err, ErrBadRequest) { // lets assume ErrBadRequest is a critical error that needs to terminate the invoke
+ return err, false // flag the second return value as false to terminate the invoke
+ }
+
+ return err, true
+ }
+
+ return nil, false
+})
+```
+
+For more advanced retry strategies (delay, exponential backoff...), please take a look on [cenkalti/backoff](https://github.com/cenkalti/backoff).
+
+[[play](https://go.dev/play/p/cfcmhvLO-nv)]
+
+### Debounce
+
+`NewDebounce` creates a debounced instance that delays invoking functions given until after wait milliseconds have elapsed, until `cancel` is called.
+
+```go
+f := func() {
+ println("Called once after 100ms when debounce stopped invoking!")
+}
+
+debounce, cancel := lo.NewDebounce(100 * time.Millisecond, f)
+for j := 0; j < 10; j++ {
+ debounce()
+}
+
+time.Sleep(1 * time.Second)
+cancel()
+```
+
+[[play](https://go.dev/play/p/mz32VMK2nqe)]
+
+### DebounceBy
+
+`NewDebounceBy` creates a debounced instance for each distinct key, that delays invoking functions given until after wait milliseconds have elapsed, until `cancel` is called.
+
+```go
+f := func(key string, count int) {
+ println(key + ": Called once after 100ms when debounce stopped invoking!")
+}
+
+debounce, cancel := lo.NewDebounceBy(100 * time.Millisecond, f)
+for j := 0; j < 10; j++ {
+ debounce("first key")
+ debounce("second key")
+}
+
+time.Sleep(1 * time.Second)
+cancel("first key")
+cancel("second key")
+```
+
+[[play](https://go.dev/play/p/d3Vpt6pxhY8)]
+
+### Throttle
+
+Creates a throttled instance that invokes given functions only once in every interval.
+
+This returns 2 functions, First one is throttled function and Second one is a function to reset interval.
+
+```go
+f := func() {
+ println("Called once in every 100ms")
+}
+
+throttle, reset := lo.NewThrottle(100 * time.Millisecond, f)
+
+for j := 0; j < 10; j++ {
+ throttle()
+ time.Sleep(30 * time.Millisecond)
+}
+
+reset()
+throttle()
+```
+
+`NewThrottleWithCount` is NewThrottle with count limit, throttled function will be invoked count times in every interval.
+
+```go
+f := func() {
+ println("Called three times in every 100ms")
+}
+
+throttle, reset := lo.NewThrottleWithCount(100 * time.Millisecond, f)
+
+for j := 0; j < 10; j++ {
+ throttle()
+ time.Sleep(30 * time.Millisecond)
+}
+
+reset()
+throttle()
+```
+
+`NewThrottleBy` and `NewThrottleByWithCount` are NewThrottle with sharding key, throttled function will be invoked count times in every interval.
+
+```go
+f := func(key string) {
+ println(key, "Called three times in every 100ms")
+}
+
+throttle, reset := lo.NewThrottleByWithCount(100 * time.Millisecond, f)
+
+for j := 0; j < 10; j++ {
+ throttle("foo")
+ time.Sleep(30 * time.Millisecond)
+}
+
+reset()
+throttle()
+```
+
+### Synchronize
+
+Wraps the underlying callback in a mutex. It receives an optional mutex.
+
+```go
+s := lo.Synchronize()
+
+for i := 0; i < 10; i++ {
+ go s.Do(func () {
+ println("will be called sequentially")
+ })
+}
+```
+
+It is equivalent to:
+
+```go
+mu := sync.Mutex{}
+
+func foobar() {
+ mu.Lock()
+ defer mu.Unlock()
+
+ // ...
+}
+```
+
+### Async
+
+Executes a function in a goroutine and returns the result in a channel.
+
+```go
+ch := lo.Async(func() error { time.Sleep(10 * time.Second); return nil })
+// chan error (nil)
+```
+
+### Async{0->6}
+
+Executes a function in a goroutine and returns the result in a channel.
+For function with multiple return values, the results will be returned as a tuple inside the channel.
+For function without return, struct{} will be returned in the channel.
+
+```go
+ch := lo.Async0(func() { time.Sleep(10 * time.Second) })
+// chan struct{}
+
+ch := lo.Async1(func() int {
+ time.Sleep(10 * time.Second);
+ return 42
+})
+// chan int (42)
+
+ch := lo.Async2(func() (int, string) {
+ time.Sleep(10 * time.Second);
+ return 42, "Hello"
+})
+// chan lo.Tuple2[int, string] ({42, "Hello"})
+```
+
+### Transaction
+
+Implements a Saga pattern.
+
+```go
+transaction := NewTransaction().
+ Then(
+ func(state int) (int, error) {
+ fmt.Println("step 1")
+ return state + 10, nil
+ },
+ func(state int) int {
+ fmt.Println("rollback 1")
+ return state - 10
+ },
+ ).
+ Then(
+ func(state int) (int, error) {
+ fmt.Println("step 2")
+ return state + 15, nil
+ },
+ func(state int) int {
+ fmt.Println("rollback 2")
+ return state - 15
+ },
+ ).
+ Then(
+ func(state int) (int, error) {
+ fmt.Println("step 3")
+
+ if true {
+ return state, fmt.Errorf("error")
+ }
+
+ return state + 42, nil
+ },
+ func(state int) int {
+ fmt.Println("rollback 3")
+ return state - 42
+ },
+ )
+
+_, _ = transaction.Process(-5)
+
+// Output:
+// step 1
+// step 2
+// step 3
+// rollback 2
+// rollback 1
+```
+
+### WaitFor
+
+Runs periodically until a condition is validated.
+
+```go
+alwaysTrue := func(i int) bool { return true }
+alwaysFalse := func(i int) bool { return false }
+laterTrue := func(i int) bool {
+ return i > 5
+}
+
+iterations, duration, ok := lo.WaitFor(alwaysTrue, 10*time.Millisecond, 2 * time.Millisecond)
+// 1
+// 1ms
+// true
+
+iterations, duration, ok := lo.WaitFor(alwaysFalse, 10*time.Millisecond, time.Millisecond)
+// 10
+// 10ms
+// false
+
+iterations, duration, ok := lo.WaitFor(laterTrue, 10*time.Millisecond, time.Millisecond)
+// 7
+// 7ms
+// true
+
+iterations, duration, ok := lo.WaitFor(laterTrue, 10*time.Millisecond, 5*time.Millisecond)
+// 2
+// 10ms
+// false
+```
+
+### WaitForWithContext
+
+Runs periodically until a condition is validated or context is invalid.
+
+The condition receives also the context, so it can invalidate the process in the condition checker
+
+```go
+ctx := context.Background()
+
+alwaysTrue := func(_ context.Context, i int) bool { return true }
+alwaysFalse := func(_ context.Context, i int) bool { return false }
+laterTrue := func(_ context.Context, i int) bool {
+ return i >= 5
+}
+
+iterations, duration, ok := lo.WaitForWithContext(ctx, alwaysTrue, 10*time.Millisecond, 2 * time.Millisecond)
+// 1
+// 1ms
+// true
+
+iterations, duration, ok := lo.WaitForWithContext(ctx, alwaysFalse, 10*time.Millisecond, time.Millisecond)
+// 10
+// 10ms
+// false
+
+iterations, duration, ok := lo.WaitForWithContext(ctx, laterTrue, 10*time.Millisecond, time.Millisecond)
+// 5
+// 5ms
+// true
+
+iterations, duration, ok := lo.WaitForWithContext(ctx, laterTrue, 10*time.Millisecond, 5*time.Millisecond)
+// 2
+// 10ms
+// false
+
+expiringCtx, cancel := context.WithTimeout(ctx, 5*time.Millisecond)
+iterations, duration, ok := lo.WaitForWithContext(expiringCtx, alwaysFalse, 100*time.Millisecond, time.Millisecond)
+// 5
+// 5.1ms
+// false
+```
+
+### Validate
+
+Helper function that creates an error when a condition is not met.
+
+```go
+slice := []string{"a"}
+val := lo.Validate(len(slice) == 0, "Slice should be empty but contains %v", slice)
+// error("Slice should be empty but contains [a]")
+
+slice := []string{}
+val := lo.Validate(len(slice) == 0, "Slice should be empty but contains %v", slice)
+// nil
+```
+
+[[play](https://go.dev/play/p/vPyh51XpCBt)]
+
+### Must
+
+Wraps a function call to panics if second argument is `error` or `false`, returns the value otherwise.
+
+```go
+val := lo.Must(time.Parse("2006-01-02", "2022-01-15"))
+// 2022-01-15
+
+val := lo.Must(time.Parse("2006-01-02", "bad-value"))
+// panics
+```
+
+[[play](https://go.dev/play/p/TMoWrRp3DyC)]
+
+### Must{0->6}
+
+Must\* has the same behavior as Must, but returns multiple values.
+
+```go
+func example0() (error)
+func example1() (int, error)
+func example2() (int, string, error)
+func example3() (int, string, time.Date, error)
+func example4() (int, string, time.Date, bool, error)
+func example5() (int, string, time.Date, bool, float64, error)
+func example6() (int, string, time.Date, bool, float64, byte, error)
+
+lo.Must0(example0())
+val1 := lo.Must1(example1()) // alias to Must
+val1, val2 := lo.Must2(example2())
+val1, val2, val3 := lo.Must3(example3())
+val1, val2, val3, val4 := lo.Must4(example4())
+val1, val2, val3, val4, val5 := lo.Must5(example5())
+val1, val2, val3, val4, val5, val6 := lo.Must6(example6())
+```
+
+You can wrap functions like `func (...) (..., ok bool)`.
+
+```go
+// math.Signbit(float64) bool
+lo.Must0(math.Signbit(v))
+
+// bytes.Cut([]byte,[]byte) ([]byte, []byte, bool)
+before, after := lo.Must2(bytes.Cut(s, sep))
+```
+
+You can give context to the panic message by adding some printf-like arguments.
+
+```go
+val, ok := lo.Find(myString, func(i string) bool {
+ return i == requiredChar
+})
+lo.Must0(ok, "'%s' must always contain '%s'", myString, requiredChar)
+
+list := []int{0, 1, 2}
+item := 5
+lo.Must0(lo.Contains(list, item), "'%s' must always contain '%s'", list, item)
+...
+```
+
+[[play](https://go.dev/play/p/TMoWrRp3DyC)]
+
+### Try
+
+Calls the function and returns false in case of error and panic.
+
+```go
+ok := lo.Try(func() error {
+ panic("error")
+ return nil
+})
+// false
+
+ok := lo.Try(func() error {
+ return nil
+})
+// true
+
+ok := lo.Try(func() error {
+ return fmt.Errorf("error")
+})
+// false
+```
+
+[[play](https://go.dev/play/p/mTyyWUvn9u4)]
+
+### Try{0->6}
+
+The same behavior as `Try`, but the callback returns 2 variables.
+
+```go
+ok := lo.Try2(func() (string, error) {
+ panic("error")
+ return "", nil
+})
+// false
+```
+
+[[play](https://go.dev/play/p/mTyyWUvn9u4)]
+
+### TryOr
+
+Calls the function and return a default value in case of error and on panic.
+
+```go
+str, ok := lo.TryOr(func() (string, error) {
+ panic("error")
+ return "hello", nil
+}, "world")
+// world
+// false
+
+str, ok := lo.TryOr(func() error {
+ return "hello", nil
+}, "world")
+// hello
+// true
+
+str, ok := lo.TryOr(func() error {
+ return "hello", fmt.Errorf("error")
+}, "world")
+// world
+// false
+```
+
+[[play](https://go.dev/play/p/B4F7Wg2Zh9X)]
+
+### TryOr{0->6}
+
+The same behavior as `TryOr`, but the callback returns `X` variables.
+
+```go
+str, nbr, ok := lo.TryOr2(func() (string, int, error) {
+ panic("error")
+ return "hello", 42, nil
+}, "world", 21)
+// world
+// 21
+// false
+```
+
+[[play](https://go.dev/play/p/B4F7Wg2Zh9X)]
+
+### TryWithErrorValue
+
+The same behavior as `Try`, but also returns the value passed to panic.
+
+```go
+err, ok := lo.TryWithErrorValue(func() error {
+ panic("error")
+ return nil
+})
+// "error", false
+```
+
+[[play](https://go.dev/play/p/Kc7afQIT2Fs)]
+
+### TryCatch
+
+The same behavior as `Try`, but calls the catch function in case of error.
+
+```go
+caught := false
+
+ok := lo.TryCatch(func() error {
+ panic("error")
+ return nil
+}, func() {
+ caught = true
+})
+// false
+// caught == true
+```
+
+[[play](https://go.dev/play/p/PnOON-EqBiU)]
+
+### TryCatchWithErrorValue
+
+The same behavior as `TryWithErrorValue`, but calls the catch function in case of error.
+
+```go
+caught := false
+
+ok := lo.TryCatchWithErrorValue(func() error {
+ panic("error")
+ return nil
+}, func(val any) {
+ caught = val == "error"
+})
+// false
+// caught == true
+```
+
+[[play](https://go.dev/play/p/8Pc9gwX_GZO)]
+
+### ErrorsAs
+
+A shortcut for:
+
+```go
+err := doSomething()
+
+var rateLimitErr *RateLimitError
+if ok := errors.As(err, &rateLimitErr); ok {
+ // retry later
+}
+```
+
+1 line `lo` helper:
+
+```go
+err := doSomething()
+
+if rateLimitErr, ok := lo.ErrorsAs[*RateLimitError](err); ok {
+ // retry later
+}
+```
+
+[[play](https://go.dev/play/p/8wk5rH8UfrE)]
+
+### Assert
+
+Does nothing when the condition is `true`, otherwise it panics with an optional message.
+
+Think twice before using it, given that [Go intentionally omits assertions from its standard library](https://go.dev/doc/faq#assertions).
+
+```go
+age := getUserAge()
+
+lo.Assert(age >= 15)
+```
+
+```go
+age := getUserAge()
+
+lo.Assert(age >= 15, "user age must be >= 15")
+```
+
+[[play](https://go.dev/play/p/Xv8LLKBMNwI)]
+
+### Assertf
+
+Like `Assert`, but with `fmt.Printf`-like formatting.
+
+Think twice before using it, given that [Go intentionally omits assertions from its standard library](https://go.dev/doc/faq#assertions).
+
+```go
+age := getUserAge()
+
+lo.Assertf(age >= 15, "user age must be >= 15, got %d", age)
+```
+
+[[play](https://go.dev/play/p/TVPEmVcyrdY)]
+
+## 🛩 Benchmark
+
+We executed a simple benchmark with a dead-simple `lo.Map` loop:
+
+See the full implementation [here](./map_benchmark_test.go).
+
+```go
+_ = lo.Map[int64](arr, func(x int64, i int) string {
+ return strconv.FormatInt(x, 10)
+})
+```
+
+**Result:**
+
+Here is a comparison between `lo.Map`, `lop.Map`, `go-funk` library and a simple Go `for` loop.
+
+```shell
+$ go test -benchmem -bench ./...
+goos: linux
+goarch: amd64
+pkg: github.com/samber/lo
+cpu: Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
+cpu: Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
+BenchmarkMap/lo.Map-8 8 132728237 ns/op 39998945 B/op 1000002 allocs/op
+BenchmarkMap/lop.Map-8 2 503947830 ns/op 119999956 B/op 3000007 allocs/op
+BenchmarkMap/reflect-8 2 826400560 ns/op 170326512 B/op 4000042 allocs/op
+BenchmarkMap/for-8 9 126252954 ns/op 39998674 B/op 1000001 allocs/op
+PASS
+ok github.com/samber/lo 6.657s
+```
+
+- `lo.Map` is way faster (x7) than `go-funk`, a reflection-based Map implementation.
+- `lo.Map` has the same allocation profile as `for`.
+- `lo.Map` is 4% slower than `for`.
+- `lop.Map` is slower than `lo.Map` because it implies more memory allocation and locks. `lop.Map` will be useful for long-running callbacks, such as i/o bound processing.
+- `for` beats other implementations for memory and CPU.
+
+## 🤝 Contributing
+
+- Ping me on Twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
+- Fork the [project](https://github.com/samber/lo)
+- Fix [open issues](https://github.com/samber/lo/issues) or request new features
+
+Don't hesitate ;)
+
+Helper naming: helpers must be self-explanatory and respect standards (other languages, libraries...). Feel free to suggest many names in your contributions.
+
+### With Docker
+
+```bash
+docker-compose run --rm dev
+```
+
+### Without Docker
+
+```bash
+# Install some dev dependencies
+make tools
+
+# Run tests
+make test
+# or
+make watch-test
+```
+
+## 👤 Contributors
+
+![Contributors](https://contrib.rocks/image?repo=samber/lo)
+
+## 💫 Show your support
+
+Give a ⭐️ if this project helped you!
+
+[![GitHub Sponsors](https://img.shields.io/github/sponsors/samber?style=for-the-badge)](https://github.com/sponsors/samber)
+
+## 📝 License
+
+Copyright © 2022 [Samuel Berthe](https://github.com/samber).
+
+This project is under [MIT](./LICENSE) license.
diff --git a/vendor/github.com/samber/lo/channel.go b/vendor/github.com/samber/lo/channel.go
new file mode 100644
index 00000000..a1e2cddc
--- /dev/null
+++ b/vendor/github.com/samber/lo/channel.go
@@ -0,0 +1,314 @@
+package lo
+
+import (
+ "context"
+ "sync"
+ "time"
+
+ "github.com/samber/lo/internal/rand"
+)
+
+type DispatchingStrategy[T any] func(msg T, index uint64, channels []<-chan T) int
+
+// ChannelDispatcher distributes messages from input channels into N child channels.
+// Close events are propagated to children.
+// Underlying channels can have a fixed buffer capacity or be unbuffered when cap is 0.
+func ChannelDispatcher[T any](stream <-chan T, count int, channelBufferCap int, strategy DispatchingStrategy[T]) []<-chan T {
+ children := createChannels[T](count, channelBufferCap)
+
+ roChildren := channelsToReadOnly(children)
+
+ go func() {
+ // propagate channel closing to children
+ defer closeChannels(children)
+
+ var i uint64 = 0
+
+ for {
+ msg, ok := <-stream
+ if !ok {
+ return
+ }
+
+ destination := strategy(msg, i, roChildren) % count
+ children[destination] <- msg
+
+ i++
+ }
+ }()
+
+ return roChildren
+}
+
+func createChannels[T any](count int, channelBufferCap int) []chan T {
+ children := make([]chan T, 0, count)
+
+ for i := 0; i < count; i++ {
+ children = append(children, make(chan T, channelBufferCap))
+ }
+
+ return children
+}
+
+func channelsToReadOnly[T any](children []chan T) []<-chan T {
+ roChildren := make([]<-chan T, 0, len(children))
+
+ for i := range children {
+ roChildren = append(roChildren, children[i])
+ }
+
+ return roChildren
+}
+
+func closeChannels[T any](children []chan T) {
+ for i := 0; i < len(children); i++ {
+ close(children[i])
+ }
+}
+
+func channelIsNotFull[T any](ch <-chan T) bool {
+ return cap(ch) == 0 || len(ch) < cap(ch)
+}
+
+// DispatchingStrategyRoundRobin distributes messages in a rotating sequential manner.
+// If the channel capacity is exceeded, the next channel will be selected and so on.
+func DispatchingStrategyRoundRobin[T any](msg T, index uint64, channels []<-chan T) int {
+ for {
+ i := int(index % uint64(len(channels)))
+ if channelIsNotFull(channels[i]) {
+ return i
+ }
+
+ index++
+ time.Sleep(10 * time.Microsecond) // prevent CPU from burning 🔥
+ }
+}
+
+// DispatchingStrategyRandom distributes messages in a random manner.
+// If the channel capacity is exceeded, another random channel will be selected and so on.
+func DispatchingStrategyRandom[T any](msg T, index uint64, channels []<-chan T) int {
+ for {
+ i := rand.IntN(len(channels))
+ if channelIsNotFull(channels[i]) {
+ return i
+ }
+
+ time.Sleep(10 * time.Microsecond) // prevent CPU from burning 🔥
+ }
+}
+
+// DispatchingStrategyWeightedRandom distributes messages in a weighted manner.
+// If the channel capacity is exceeded, another random channel will be selected and so on.
+func DispatchingStrategyWeightedRandom[T any](weights []int) DispatchingStrategy[T] {
+ seq := []int{}
+
+ for i := 0; i < len(weights); i++ {
+ for j := 0; j < weights[i]; j++ {
+ seq = append(seq, i)
+ }
+ }
+
+ return func(msg T, index uint64, channels []<-chan T) int {
+ for {
+ i := seq[rand.IntN(len(seq))]
+ if channelIsNotFull(channels[i]) {
+ return i
+ }
+
+ time.Sleep(10 * time.Microsecond) // prevent CPU from burning 🔥
+ }
+ }
+}
+
+// DispatchingStrategyFirst distributes messages in the first non-full channel.
+// If the capacity of the first channel is exceeded, the second channel will be selected and so on.
+func DispatchingStrategyFirst[T any](msg T, index uint64, channels []<-chan T) int {
+ for {
+ for i := range channels {
+ if channelIsNotFull(channels[i]) {
+ return i
+ }
+ }
+
+ time.Sleep(10 * time.Microsecond) // prevent CPU from burning 🔥
+ }
+}
+
+// DispatchingStrategyLeast distributes messages in the emptiest channel.
+func DispatchingStrategyLeast[T any](msg T, index uint64, channels []<-chan T) int {
+ seq := Range(len(channels))
+
+ return MinBy(seq, func(item int, min int) bool {
+ return len(channels[item]) < len(channels[min])
+ })
+}
+
+// DispatchingStrategyMost distributes messages in the fullest channel.
+// If the channel capacity is exceeded, the next channel will be selected and so on.
+func DispatchingStrategyMost[T any](msg T, index uint64, channels []<-chan T) int {
+ seq := Range(len(channels))
+
+ return MaxBy(seq, func(item int, max int) bool {
+ return len(channels[item]) > len(channels[max]) && channelIsNotFull(channels[item])
+ })
+}
+
+// SliceToChannel returns a read-only channels of collection elements.
+func SliceToChannel[T any](bufferSize int, collection []T) <-chan T {
+ ch := make(chan T, bufferSize)
+
+ go func() {
+ for i := range collection {
+ ch <- collection[i]
+ }
+
+ close(ch)
+ }()
+
+ return ch
+}
+
+// ChannelToSlice returns a slice built from channels items. Blocks until channel closes.
+func ChannelToSlice[T any](ch <-chan T) []T {
+ collection := []T{}
+
+ for item := range ch {
+ collection = append(collection, item)
+ }
+
+ return collection
+}
+
+// Generator implements the generator design pattern.
+func Generator[T any](bufferSize int, generator func(yield func(T))) <-chan T {
+ ch := make(chan T, bufferSize)
+
+ go func() {
+ // WARNING: infinite loop
+ generator(func(t T) {
+ ch <- t
+ })
+
+ close(ch)
+ }()
+
+ return ch
+}
+
+// Buffer creates a slice of n elements from a channel. Returns the slice and the slice length.
+// @TODO: we should probably provide an helper that reuse the same buffer.
+func Buffer[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool) {
+ buffer := make([]T, 0, size)
+ index := 0
+ now := time.Now()
+
+ for ; index < size; index++ {
+ item, ok := <-ch
+ if !ok {
+ return buffer, index, time.Since(now), false
+ }
+
+ buffer = append(buffer, item)
+ }
+
+ return buffer, index, time.Since(now), true
+}
+
+// Batch creates a slice of n elements from a channel. Returns the slice and the slice length.
+//
+// Deprecated: Use [Buffer] instead.
+func Batch[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool) {
+ return Buffer(ch, size)
+}
+
+// BufferWithContext creates a slice of n elements from a channel, with context. Returns the slice and the slice length.
+// @TODO: we should probably provide an helper that reuse the same buffer.
+func BufferWithContext[T any](ctx context.Context, ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool) {
+ buffer := make([]T, 0, size)
+ now := time.Now()
+
+ for index := 0; index < size; index++ {
+ select {
+ case item, ok := <-ch:
+ if !ok {
+ return buffer, index, time.Since(now), false
+ }
+
+ buffer = append(buffer, item)
+
+ case <-ctx.Done():
+ return buffer, index, time.Since(now), true
+ }
+ }
+
+ return buffer, size, time.Since(now), true
+}
+
+// BufferWithTimeout creates a slice of n elements from a channel, with timeout. Returns the slice and the slice length.
+func BufferWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool) {
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ return BufferWithContext(ctx, ch, size)
+}
+
+// BatchWithTimeout creates a slice of n elements from a channel, with timeout. Returns the slice and the slice length.
+//
+// Deprecated: Use [BufferWithTimeout] instead.
+func BatchWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool) {
+ return BufferWithTimeout(ch, size, timeout)
+}
+
+// FanIn collects messages from multiple input channels into a single buffered channel.
+// Output messages has no priority. When all upstream channels reach EOF, downstream channel closes.
+func FanIn[T any](channelBufferCap int, upstreams ...<-chan T) <-chan T {
+ out := make(chan T, channelBufferCap)
+ var wg sync.WaitGroup
+
+ // Start an output goroutine for each input channel in upstreams.
+ wg.Add(len(upstreams))
+ for i := range upstreams {
+ go func(index int) {
+ for n := range upstreams[index] {
+ out <- n
+ }
+ wg.Done()
+ }(i)
+ }
+
+ // Start a goroutine to close out once all the output goroutines are done.
+ go func() {
+ wg.Wait()
+ close(out)
+ }()
+ return out
+}
+
+// ChannelMerge collects messages from multiple input channels into a single buffered channel.
+// Output messages has no priority. When all upstream channels reach EOF, downstream channel closes.
+//
+// Deprecated: Use [FanIn] instead.
+func ChannelMerge[T any](channelBufferCap int, upstreams ...<-chan T) <-chan T {
+ return FanIn(channelBufferCap, upstreams...)
+}
+
+// FanOut broadcasts all the upstream messages to multiple downstream channels.
+// When upstream channel reach EOF, downstream channels close. If any downstream
+// channels is full, broadcasting is paused.
+func FanOut[T any](count int, channelsBufferCap int, upstream <-chan T) []<-chan T {
+ downstreams := createChannels[T](count, channelsBufferCap)
+
+ go func() {
+ for msg := range upstream {
+ for i := range downstreams {
+ downstreams[i] <- msg
+ }
+ }
+
+ // Close out once all the output goroutines are done.
+ for i := range downstreams {
+ close(downstreams[i])
+ }
+ }()
+
+ return channelsToReadOnly(downstreams)
+}
diff --git a/vendor/github.com/samber/lo/concurrency.go b/vendor/github.com/samber/lo/concurrency.go
new file mode 100644
index 00000000..a2ebbce2
--- /dev/null
+++ b/vendor/github.com/samber/lo/concurrency.go
@@ -0,0 +1,136 @@
+package lo
+
+import (
+ "context"
+ "sync"
+ "time"
+)
+
+type synchronize struct {
+ locker sync.Locker
+}
+
+func (s *synchronize) Do(cb func()) {
+ s.locker.Lock()
+ Try0(cb)
+ s.locker.Unlock()
+}
+
+// Synchronize wraps the underlying callback in a mutex. It receives an optional mutex.
+func Synchronize(opt ...sync.Locker) *synchronize {
+ if len(opt) > 1 {
+ panic("unexpected arguments")
+ } else if len(opt) == 0 {
+ opt = append(opt, &sync.Mutex{})
+ }
+
+ return &synchronize{
+ locker: opt[0],
+ }
+}
+
+// Async executes a function in a goroutine and returns the result in a channel.
+func Async[A any](f func() A) <-chan A {
+ ch := make(chan A, 1)
+ go func() {
+ ch <- f()
+ }()
+ return ch
+}
+
+// Async0 executes a function in a goroutine and returns a channel set once the function finishes.
+func Async0(f func()) <-chan struct{} {
+ ch := make(chan struct{}, 1)
+ go func() {
+ f()
+ ch <- struct{}{}
+ }()
+ return ch
+}
+
+// Async1 is an alias to Async.
+func Async1[A any](f func() A) <-chan A {
+ return Async(f)
+}
+
+// Async2 has the same behavior as Async, but returns the 2 results as a tuple inside the channel.
+func Async2[A, B any](f func() (A, B)) <-chan Tuple2[A, B] {
+ ch := make(chan Tuple2[A, B], 1)
+ go func() {
+ ch <- T2(f())
+ }()
+ return ch
+}
+
+// Async3 has the same behavior as Async, but returns the 3 results as a tuple inside the channel.
+func Async3[A, B, C any](f func() (A, B, C)) <-chan Tuple3[A, B, C] {
+ ch := make(chan Tuple3[A, B, C], 1)
+ go func() {
+ ch <- T3(f())
+ }()
+ return ch
+}
+
+// Async4 has the same behavior as Async, but returns the 4 results as a tuple inside the channel.
+func Async4[A, B, C, D any](f func() (A, B, C, D)) <-chan Tuple4[A, B, C, D] {
+ ch := make(chan Tuple4[A, B, C, D], 1)
+ go func() {
+ ch <- T4(f())
+ }()
+ return ch
+}
+
+// Async5 has the same behavior as Async, but returns the 5 results as a tuple inside the channel.
+func Async5[A, B, C, D, E any](f func() (A, B, C, D, E)) <-chan Tuple5[A, B, C, D, E] {
+ ch := make(chan Tuple5[A, B, C, D, E], 1)
+ go func() {
+ ch <- T5(f())
+ }()
+ return ch
+}
+
+// Async6 has the same behavior as Async, but returns the 6 results as a tuple inside the channel.
+func Async6[A, B, C, D, E, F any](f func() (A, B, C, D, E, F)) <-chan Tuple6[A, B, C, D, E, F] {
+ ch := make(chan Tuple6[A, B, C, D, E, F], 1)
+ go func() {
+ ch <- T6(f())
+ }()
+ return ch
+}
+
+// WaitFor runs periodically until a condition is validated.
+func WaitFor(condition func(i int) bool, timeout time.Duration, heartbeatDelay time.Duration) (totalIterations int, elapsed time.Duration, conditionFound bool) {
+ conditionWithContext := func(_ context.Context, currentIteration int) bool {
+ return condition(currentIteration)
+ }
+ return WaitForWithContext(context.Background(), conditionWithContext, timeout, heartbeatDelay)
+}
+
+// WaitForWithContext runs periodically until a condition is validated or context is canceled.
+func WaitForWithContext(ctx context.Context, condition func(ctx context.Context, currentIteration int) bool, timeout time.Duration, heartbeatDelay time.Duration) (totalIterations int, elapsed time.Duration, conditionFound bool) {
+ start := time.Now()
+
+ if ctx.Err() != nil {
+ return totalIterations, time.Since(start), false
+ }
+
+ ctx, cleanCtx := context.WithTimeout(ctx, timeout)
+ ticker := time.NewTicker(heartbeatDelay)
+
+ defer func() {
+ cleanCtx()
+ ticker.Stop()
+ }()
+
+ for {
+ select {
+ case <-ctx.Done():
+ return totalIterations, time.Since(start), false
+ case <-ticker.C:
+ totalIterations++
+ if condition(ctx, totalIterations-1) {
+ return totalIterations, time.Since(start), true
+ }
+ }
+ }
+}
diff --git a/vendor/github.com/samber/lo/condition.go b/vendor/github.com/samber/lo/condition.go
new file mode 100644
index 00000000..eaeaa2b9
--- /dev/null
+++ b/vendor/github.com/samber/lo/condition.go
@@ -0,0 +1,151 @@
+package lo
+
+// Ternary is a 1 line if/else statement.
+// Take care to avoid dereferencing potentially nil pointers in your A/B expressions, because they are both evaluated. See TernaryF to avoid this problem.
+// Play: https://go.dev/play/p/t-D7WBL44h2
+func Ternary[T any](condition bool, ifOutput T, elseOutput T) T {
+ if condition {
+ return ifOutput
+ }
+
+ return elseOutput
+}
+
+// TernaryF is a 1 line if/else statement whose options are functions
+// Play: https://go.dev/play/p/AO4VW20JoqM
+func TernaryF[T any](condition bool, ifFunc func() T, elseFunc func() T) T {
+ if condition {
+ return ifFunc()
+ }
+
+ return elseFunc()
+}
+
+type ifElse[T any] struct {
+ result T
+ done bool
+}
+
+// If.
+// Play: https://go.dev/play/p/WSw3ApMxhyW
+func If[T any](condition bool, result T) *ifElse[T] {
+ if condition {
+ return &ifElse[T]{result, true}
+ }
+
+ var t T
+ return &ifElse[T]{t, false}
+}
+
+// IfF.
+// Play: https://go.dev/play/p/WSw3ApMxhyW
+func IfF[T any](condition bool, resultF func() T) *ifElse[T] {
+ if condition {
+ return &ifElse[T]{resultF(), true}
+ }
+
+ var t T
+ return &ifElse[T]{t, false}
+}
+
+// ElseIf.
+// Play: https://go.dev/play/p/WSw3ApMxhyW
+func (i *ifElse[T]) ElseIf(condition bool, result T) *ifElse[T] {
+ if !i.done && condition {
+ i.result = result
+ i.done = true
+ }
+
+ return i
+}
+
+// ElseIfF.
+// Play: https://go.dev/play/p/WSw3ApMxhyW
+func (i *ifElse[T]) ElseIfF(condition bool, resultF func() T) *ifElse[T] {
+ if !i.done && condition {
+ i.result = resultF()
+ i.done = true
+ }
+
+ return i
+}
+
+// Else.
+// Play: https://go.dev/play/p/WSw3ApMxhyW
+func (i *ifElse[T]) Else(result T) T {
+ if i.done {
+ return i.result
+ }
+
+ return result
+}
+
+// ElseF.
+// Play: https://go.dev/play/p/WSw3ApMxhyW
+func (i *ifElse[T]) ElseF(resultF func() T) T {
+ if i.done {
+ return i.result
+ }
+
+ return resultF()
+}
+
+type switchCase[T comparable, R any] struct {
+ predicate T
+ result R
+ done bool
+}
+
+// Switch is a pure functional switch/case/default statement.
+// Play: https://go.dev/play/p/TGbKUMAeRUd
+func Switch[T comparable, R any](predicate T) *switchCase[T, R] {
+ var result R
+
+ return &switchCase[T, R]{
+ predicate,
+ result,
+ false,
+ }
+}
+
+// Case.
+// Play: https://go.dev/play/p/TGbKUMAeRUd
+func (s *switchCase[T, R]) Case(val T, result R) *switchCase[T, R] {
+ if !s.done && s.predicate == val {
+ s.result = result
+ s.done = true
+ }
+
+ return s
+}
+
+// CaseF.
+// Play: https://go.dev/play/p/TGbKUMAeRUd
+func (s *switchCase[T, R]) CaseF(val T, cb func() R) *switchCase[T, R] {
+ if !s.done && s.predicate == val {
+ s.result = cb()
+ s.done = true
+ }
+
+ return s
+}
+
+// Default.
+// Play: https://go.dev/play/p/TGbKUMAeRUd
+func (s *switchCase[T, R]) Default(result R) R {
+ if !s.done {
+ s.result = result
+ }
+
+ return s.result
+}
+
+// DefaultF.
+// Play: https://go.dev/play/p/TGbKUMAeRUd
+func (s *switchCase[T, R]) DefaultF(cb func() R) R {
+ if !s.done {
+ s.result = cb()
+ }
+
+ return s.result
+}
diff --git a/vendor/github.com/samber/lo/constraints.go b/vendor/github.com/samber/lo/constraints.go
new file mode 100644
index 00000000..c1f35296
--- /dev/null
+++ b/vendor/github.com/samber/lo/constraints.go
@@ -0,0 +1,6 @@
+package lo
+
+// Clonable defines a constraint of types having Clone() T method.
+type Clonable[T any] interface {
+ Clone() T
+}
diff --git a/vendor/github.com/samber/lo/errors.go b/vendor/github.com/samber/lo/errors.go
new file mode 100644
index 00000000..a2347218
--- /dev/null
+++ b/vendor/github.com/samber/lo/errors.go
@@ -0,0 +1,381 @@
+package lo
+
+import (
+ "errors"
+ "fmt"
+ "reflect"
+)
+
+const defaultAssertionFailureMessage = "assertion failed"
+
+// Validate is a helper that creates an error when a condition is not met.
+// Play: https://go.dev/play/p/vPyh51XpCBt
+func Validate(ok bool, format string, args ...any) error {
+ if !ok {
+ return fmt.Errorf(format, args...)
+ }
+ return nil
+}
+
+func messageFromMsgAndArgs(msgAndArgs ...any) string {
+ if len(msgAndArgs) == 1 {
+ if msgAsStr, ok := msgAndArgs[0].(string); ok {
+ return msgAsStr
+ }
+ return fmt.Sprintf("%+v", msgAndArgs[0])
+ }
+ if len(msgAndArgs) > 1 {
+ return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
+ }
+ return ""
+}
+
+// must panics if err is error or false.
+func must(err any, messageArgs ...any) {
+ if err == nil {
+ return
+ }
+
+ switch e := err.(type) {
+ case bool:
+ if !e {
+ message := messageFromMsgAndArgs(messageArgs...)
+ if message == "" {
+ message = "not ok"
+ }
+
+ panic(message)
+ }
+
+ case error:
+ message := messageFromMsgAndArgs(messageArgs...)
+ if message != "" {
+ panic(message + ": " + e.Error())
+ } else {
+ panic(e.Error())
+ }
+
+ default:
+ panic("must: invalid err type '" + reflect.TypeOf(err).Name() + "', should either be a bool or an error")
+ }
+}
+
+// Must is a helper that wraps a call to a function returning a value and an error
+// and panics if err is error or false.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must[T any](val T, err any, messageArgs ...any) T {
+ must(err, messageArgs...)
+ return val
+}
+
+// Must0 has the same behavior as Must, but callback returns no variable.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must0(err any, messageArgs ...any) {
+ must(err, messageArgs...)
+}
+
+// Must1 is an alias to Must
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must1[T any](val T, err any, messageArgs ...any) T {
+ return Must(val, err, messageArgs...)
+}
+
+// Must2 has the same behavior as Must, but callback returns 2 variables.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must2[T1, T2 any](val1 T1, val2 T2, err any, messageArgs ...any) (T1, T2) {
+ must(err, messageArgs...)
+ return val1, val2
+}
+
+// Must3 has the same behavior as Must, but callback returns 3 variables.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must3[T1, T2, T3 any](val1 T1, val2 T2, val3 T3, err any, messageArgs ...any) (T1, T2, T3) {
+ must(err, messageArgs...)
+ return val1, val2, val3
+}
+
+// Must4 has the same behavior as Must, but callback returns 4 variables.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must4[T1, T2, T3, T4 any](val1 T1, val2 T2, val3 T3, val4 T4, err any, messageArgs ...any) (T1, T2, T3, T4) {
+ must(err, messageArgs...)
+ return val1, val2, val3, val4
+}
+
+// Must5 has the same behavior as Must, but callback returns 5 variables.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must5[T1, T2, T3, T4, T5 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err any, messageArgs ...any) (T1, T2, T3, T4, T5) {
+ must(err, messageArgs...)
+ return val1, val2, val3, val4, val5
+}
+
+// Must6 has the same behavior as Must, but callback returns 6 variables.
+// Play: https://go.dev/play/p/TMoWrRp3DyC
+func Must6[T1, T2, T3, T4, T5, T6 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, val6 T6, err any, messageArgs ...any) (T1, T2, T3, T4, T5, T6) {
+ must(err, messageArgs...)
+ return val1, val2, val3, val4, val5, val6
+}
+
+// Try calls the function and return false in case of error.
+func Try(callback func() error) (ok bool) {
+ ok = true
+
+ defer func() {
+ if r := recover(); r != nil {
+ ok = false
+ }
+ }()
+
+ err := callback()
+ if err != nil {
+ ok = false
+ }
+
+ return
+}
+
+// Try0 has the same behavior as Try, but callback returns no variable.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try0(callback func()) bool {
+ return Try(func() error {
+ callback()
+ return nil
+ })
+}
+
+// Try1 is an alias to Try.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try1(callback func() error) bool {
+ return Try(callback)
+}
+
+// Try2 has the same behavior as Try, but callback returns 2 variables.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try2[T any](callback func() (T, error)) bool {
+ return Try(func() error {
+ _, err := callback()
+ return err
+ })
+}
+
+// Try3 has the same behavior as Try, but callback returns 3 variables.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try3[T, R any](callback func() (T, R, error)) bool {
+ return Try(func() error {
+ _, _, err := callback()
+ return err
+ })
+}
+
+// Try4 has the same behavior as Try, but callback returns 4 variables.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try4[T, R, S any](callback func() (T, R, S, error)) bool {
+ return Try(func() error {
+ _, _, _, err := callback()
+ return err
+ })
+}
+
+// Try5 has the same behavior as Try, but callback returns 5 variables.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try5[T, R, S, Q any](callback func() (T, R, S, Q, error)) bool {
+ return Try(func() error {
+ _, _, _, _, err := callback()
+ return err
+ })
+}
+
+// Try6 has the same behavior as Try, but callback returns 6 variables.
+// Play: https://go.dev/play/p/mTyyWUvn9u4
+func Try6[T, R, S, Q, U any](callback func() (T, R, S, Q, U, error)) bool {
+ return Try(func() error {
+ _, _, _, _, _, err := callback()
+ return err
+ })
+}
+
+// TryOr has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr[A any](callback func() (A, error), fallbackA A) (A, bool) {
+ return TryOr1(callback, fallbackA)
+}
+
+// TryOr1 has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr1[A any](callback func() (A, error), fallbackA A) (A, bool) {
+ ok := false
+
+ Try0(func() {
+ a, err := callback()
+ if err == nil {
+ fallbackA = a
+ ok = true
+ }
+ })
+
+ return fallbackA, ok
+}
+
+// TryOr2 has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr2[A, B any](callback func() (A, B, error), fallbackA A, fallbackB B) (A, B, bool) {
+ ok := false
+
+ Try0(func() {
+ a, b, err := callback()
+ if err == nil {
+ fallbackA = a
+ fallbackB = b
+ ok = true
+ }
+ })
+
+ return fallbackA, fallbackB, ok
+}
+
+// TryOr3 has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr3[A, B, C any](callback func() (A, B, C, error), fallbackA A, fallbackB B, fallbackC C) (A, B, C, bool) {
+ ok := false
+
+ Try0(func() {
+ a, b, c, err := callback()
+ if err == nil {
+ fallbackA = a
+ fallbackB = b
+ fallbackC = c
+ ok = true
+ }
+ })
+
+ return fallbackA, fallbackB, fallbackC, ok
+}
+
+// TryOr4 has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr4[A, B, C, D any](callback func() (A, B, C, D, error), fallbackA A, fallbackB B, fallbackC C, fallbackD D) (A, B, C, D, bool) {
+ ok := false
+
+ Try0(func() {
+ a, b, c, d, err := callback()
+ if err == nil {
+ fallbackA = a
+ fallbackB = b
+ fallbackC = c
+ fallbackD = d
+ ok = true
+ }
+ })
+
+ return fallbackA, fallbackB, fallbackC, fallbackD, ok
+}
+
+// TryOr5 has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr5[A, B, C, D, E any](callback func() (A, B, C, D, E, error), fallbackA A, fallbackB B, fallbackC C, fallbackD D, fallbackE E) (A, B, C, D, E, bool) {
+ ok := false
+
+ Try0(func() {
+ a, b, c, d, e, err := callback()
+ if err == nil {
+ fallbackA = a
+ fallbackB = b
+ fallbackC = c
+ fallbackD = d
+ fallbackE = e
+ ok = true
+ }
+ })
+
+ return fallbackA, fallbackB, fallbackC, fallbackD, fallbackE, ok
+}
+
+// TryOr6 has the same behavior as Must, but returns a default value in case of error.
+// Play: https://go.dev/play/p/B4F7Wg2Zh9X
+func TryOr6[A, B, C, D, E, F any](callback func() (A, B, C, D, E, F, error), fallbackA A, fallbackB B, fallbackC C, fallbackD D, fallbackE E, fallbackF F) (A, B, C, D, E, F, bool) {
+ ok := false
+
+ Try0(func() {
+ a, b, c, d, e, f, err := callback()
+ if err == nil {
+ fallbackA = a
+ fallbackB = b
+ fallbackC = c
+ fallbackD = d
+ fallbackE = e
+ fallbackF = f
+ ok = true
+ }
+ })
+
+ return fallbackA, fallbackB, fallbackC, fallbackD, fallbackE, fallbackF, ok
+}
+
+// TryWithErrorValue has the same behavior as Try, but also returns value passed to panic.
+// Play: https://go.dev/play/p/Kc7afQIT2Fs
+func TryWithErrorValue(callback func() error) (errorValue any, ok bool) {
+ ok = true
+
+ defer func() {
+ if r := recover(); r != nil {
+ ok = false
+ errorValue = r
+ }
+ }()
+
+ err := callback()
+ if err != nil {
+ ok = false
+ errorValue = err
+ }
+
+ return
+}
+
+// TryCatch has the same behavior as Try, but calls the catch function in case of error.
+// Play: https://go.dev/play/p/PnOON-EqBiU
+func TryCatch(callback func() error, catch func()) {
+ if !Try(callback) {
+ catch()
+ }
+}
+
+// TryCatchWithErrorValue has the same behavior as TryWithErrorValue, but calls the catch function in case of error.
+// Play: https://go.dev/play/p/8Pc9gwX_GZO
+func TryCatchWithErrorValue(callback func() error, catch func(any)) {
+ if err, ok := TryWithErrorValue(callback); !ok {
+ catch(err)
+ }
+}
+
+// ErrorsAs is a shortcut for errors.As(err, &&T).
+// Play: https://go.dev/play/p/8wk5rH8UfrE
+func ErrorsAs[T error](err error) (T, bool) {
+ var t T
+ ok := errors.As(err, &t)
+ return t, ok
+}
+
+// Assert does nothing when the condition is true, otherwise it panics with an optional message.
+// Play: https://go.dev/play/p/Xv8LLKBMNwI
+func Assert(condition bool, message ...string) {
+ if condition {
+ return
+ }
+
+ panicMessage := defaultAssertionFailureMessage
+ if len(message) > 0 {
+ panicMessage = fmt.Sprintf("%s: %s", defaultAssertionFailureMessage, message[0])
+ }
+ panic(panicMessage)
+}
+
+// Assertf does nothing when the condition is true, otherwise it panics with a formatted message.
+// Play: https://go.dev/play/p/TVPEmVcyrdY
+func Assertf(condition bool, format string, args ...any) {
+ if condition {
+ return
+ }
+
+ panicMessage := fmt.Sprintf("%s: %s", defaultAssertionFailureMessage, fmt.Sprintf(format, args...))
+ panic(panicMessage)
+}
diff --git a/vendor/github.com/samber/lo/find.go b/vendor/github.com/samber/lo/find.go
new file mode 100644
index 00000000..f04dc082
--- /dev/null
+++ b/vendor/github.com/samber/lo/find.go
@@ -0,0 +1,651 @@
+package lo
+
+import (
+ "fmt"
+ "time"
+
+ "github.com/samber/lo/internal/constraints"
+ "github.com/samber/lo/internal/rand"
+)
+
+// IndexOf returns the index at which the first occurrence of a value is found in an array or return -1
+// if the value cannot be found.
+func IndexOf[T comparable](collection []T, element T) int {
+ for i := range collection {
+ if collection[i] == element {
+ return i
+ }
+ }
+
+ return -1
+}
+
+// LastIndexOf returns the index at which the last occurrence of a value is found in an array or return -1
+// if the value cannot be found.
+func LastIndexOf[T comparable](collection []T, element T) int {
+ length := len(collection)
+
+ for i := length - 1; i >= 0; i-- {
+ if collection[i] == element {
+ return i
+ }
+ }
+
+ return -1
+}
+
+// Find search an element in a slice based on a predicate. It returns element and true if element was found.
+func Find[T any](collection []T, predicate func(item T) bool) (T, bool) {
+ for i := range collection {
+ if predicate(collection[i]) {
+ return collection[i], true
+ }
+ }
+
+ var result T
+ return result, false
+}
+
+// FindIndexOf searches an element in a slice based on a predicate and returns the index and true.
+// It returns -1 and false if the element is not found.
+func FindIndexOf[T any](collection []T, predicate func(item T) bool) (T, int, bool) {
+ for i := range collection {
+ if predicate(collection[i]) {
+ return collection[i], i, true
+ }
+ }
+
+ var result T
+ return result, -1, false
+}
+
+// FindLastIndexOf searches last element in a slice based on a predicate and returns the index and true.
+// It returns -1 and false if the element is not found.
+func FindLastIndexOf[T any](collection []T, predicate func(item T) bool) (T, int, bool) {
+ length := len(collection)
+
+ for i := length - 1; i >= 0; i-- {
+ if predicate(collection[i]) {
+ return collection[i], i, true
+ }
+ }
+
+ var result T
+ return result, -1, false
+}
+
+// FindOrElse search an element in a slice based on a predicate. It returns the element if found or a given fallback value otherwise.
+func FindOrElse[T any](collection []T, fallback T, predicate func(item T) bool) T {
+ for i := range collection {
+ if predicate(collection[i]) {
+ return collection[i]
+ }
+ }
+
+ return fallback
+}
+
+// FindKey returns the key of the first value matching.
+func FindKey[K comparable, V comparable](object map[K]V, value V) (K, bool) {
+ for k := range object {
+ if object[k] == value {
+ return k, true
+ }
+ }
+
+ return Empty[K](), false
+}
+
+// FindKeyBy returns the key of the first element predicate returns truthy for.
+func FindKeyBy[K comparable, V any](object map[K]V, predicate func(key K, value V) bool) (K, bool) {
+ for k := range object {
+ if predicate(k, object[k]) {
+ return k, true
+ }
+ }
+
+ return Empty[K](), false
+}
+
+// FindUniques returns a slice with all the unique elements of the collection.
+// The order of result values is determined by the order they occur in the collection.
+func FindUniques[T comparable, Slice ~[]T](collection Slice) Slice {
+ isDupl := make(map[T]bool, len(collection))
+
+ for i := range collection {
+ duplicated, ok := isDupl[collection[i]]
+ if !ok {
+ isDupl[collection[i]] = false
+ } else if !duplicated {
+ isDupl[collection[i]] = true
+ }
+ }
+
+ result := make(Slice, 0, len(collection)-len(isDupl))
+
+ for i := range collection {
+ if duplicated := isDupl[collection[i]]; !duplicated {
+ result = append(result, collection[i])
+ }
+ }
+
+ return result
+}
+
+// FindUniquesBy returns a slice with all the unique elements of the collection.
+// The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is
+// invoked for each element in array to generate the criterion by which uniqueness is computed.
+func FindUniquesBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) Slice {
+ isDupl := make(map[U]bool, len(collection))
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ duplicated, ok := isDupl[key]
+ if !ok {
+ isDupl[key] = false
+ } else if !duplicated {
+ isDupl[key] = true
+ }
+ }
+
+ result := make(Slice, 0, len(collection)-len(isDupl))
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ if duplicated := isDupl[key]; !duplicated {
+ result = append(result, collection[i])
+ }
+ }
+
+ return result
+}
+
+// FindDuplicates returns a slice with the first occurrence of each duplicated elements of the collection.
+// The order of result values is determined by the order they occur in the collection.
+func FindDuplicates[T comparable, Slice ~[]T](collection Slice) Slice {
+ isDupl := make(map[T]bool, len(collection))
+
+ for i := range collection {
+ duplicated, ok := isDupl[collection[i]]
+ if !ok {
+ isDupl[collection[i]] = false
+ } else if !duplicated {
+ isDupl[collection[i]] = true
+ }
+ }
+
+ result := make(Slice, 0, len(collection)-len(isDupl))
+
+ for i := range collection {
+ if duplicated := isDupl[collection[i]]; duplicated {
+ result = append(result, collection[i])
+ isDupl[collection[i]] = false
+ }
+ }
+
+ return result
+}
+
+// FindDuplicatesBy returns a slice with the first occurrence of each duplicated elements of the collection.
+// The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is
+// invoked for each element in array to generate the criterion by which uniqueness is computed.
+func FindDuplicatesBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) Slice {
+ isDupl := make(map[U]bool, len(collection))
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ duplicated, ok := isDupl[key]
+ if !ok {
+ isDupl[key] = false
+ } else if !duplicated {
+ isDupl[key] = true
+ }
+ }
+
+ result := make(Slice, 0, len(collection)-len(isDupl))
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ if duplicated := isDupl[key]; duplicated {
+ result = append(result, collection[i])
+ isDupl[key] = false
+ }
+ }
+
+ return result
+}
+
+// Min search the minimum value of a collection.
+// Returns zero value when the collection is empty.
+func Min[T constraints.Ordered](collection []T) T {
+ var min T
+
+ if len(collection) == 0 {
+ return min
+ }
+
+ min = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if item < min {
+ min = item
+ }
+ }
+
+ return min
+}
+
+// MinIndex search the minimum value of a collection and the index of the minimum value.
+// Returns (zero value, -1) when the collection is empty.
+func MinIndex[T constraints.Ordered](collection []T) (T, int) {
+ var (
+ min T
+ index int
+ )
+
+ if len(collection) == 0 {
+ return min, -1
+ }
+
+ min = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if item < min {
+ min = item
+ index = i
+ }
+ }
+
+ return min, index
+}
+
+// MinBy search the minimum value of a collection using the given comparison function.
+// If several values of the collection are equal to the smallest value, returns the first such value.
+// Returns zero value when the collection is empty.
+func MinBy[T any](collection []T, comparison func(a T, b T) bool) T {
+ var min T
+
+ if len(collection) == 0 {
+ return min
+ }
+
+ min = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if comparison(item, min) {
+ min = item
+ }
+ }
+
+ return min
+}
+
+// MinIndexBy search the minimum value of a collection using the given comparison function and the index of the minimum value.
+// If several values of the collection are equal to the smallest value, returns the first such value.
+// Returns (zero value, -1) when the collection is empty.
+func MinIndexBy[T any](collection []T, comparison func(a T, b T) bool) (T, int) {
+ var (
+ min T
+ index int
+ )
+
+ if len(collection) == 0 {
+ return min, -1
+ }
+
+ min = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if comparison(item, min) {
+ min = item
+ index = i
+ }
+ }
+
+ return min, index
+}
+
+// Earliest search the minimum time.Time of a collection.
+// Returns zero value when the collection is empty.
+func Earliest(times ...time.Time) time.Time {
+ var min time.Time
+
+ if len(times) == 0 {
+ return min
+ }
+
+ min = times[0]
+
+ for i := 1; i < len(times); i++ {
+ item := times[i]
+
+ if item.Before(min) {
+ min = item
+ }
+ }
+
+ return min
+}
+
+// EarliestBy search the minimum time.Time of a collection using the given iteratee function.
+// Returns zero value when the collection is empty.
+func EarliestBy[T any](collection []T, iteratee func(item T) time.Time) T {
+ var earliest T
+
+ if len(collection) == 0 {
+ return earliest
+ }
+
+ earliest = collection[0]
+ earliestTime := iteratee(collection[0])
+
+ for i := 1; i < len(collection); i++ {
+ itemTime := iteratee(collection[i])
+
+ if itemTime.Before(earliestTime) {
+ earliest = collection[i]
+ earliestTime = itemTime
+ }
+ }
+
+ return earliest
+}
+
+// Max searches the maximum value of a collection.
+// Returns zero value when the collection is empty.
+func Max[T constraints.Ordered](collection []T) T {
+ var max T
+
+ if len(collection) == 0 {
+ return max
+ }
+
+ max = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if item > max {
+ max = item
+ }
+ }
+
+ return max
+}
+
+// MaxIndex searches the maximum value of a collection and the index of the maximum value.
+// Returns (zero value, -1) when the collection is empty.
+func MaxIndex[T constraints.Ordered](collection []T) (T, int) {
+ var (
+ max T
+ index int
+ )
+
+ if len(collection) == 0 {
+ return max, -1
+ }
+
+ max = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if item > max {
+ max = item
+ index = i
+ }
+ }
+
+ return max, index
+}
+
+// MaxBy search the maximum value of a collection using the given comparison function.
+// If several values of the collection are equal to the greatest value, returns the first such value.
+// Returns zero value when the collection is empty.
+func MaxBy[T any](collection []T, comparison func(a T, b T) bool) T {
+ var max T
+
+ if len(collection) == 0 {
+ return max
+ }
+
+ max = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if comparison(item, max) {
+ max = item
+ }
+ }
+
+ return max
+}
+
+// MaxIndexBy search the maximum value of a collection using the given comparison function and the index of the maximum value.
+// If several values of the collection are equal to the greatest value, returns the first such value.
+// Returns (zero value, -1) when the collection is empty.
+func MaxIndexBy[T any](collection []T, comparison func(a T, b T) bool) (T, int) {
+ var (
+ max T
+ index int
+ )
+
+ if len(collection) == 0 {
+ return max, -1
+ }
+
+ max = collection[0]
+
+ for i := 1; i < len(collection); i++ {
+ item := collection[i]
+
+ if comparison(item, max) {
+ max = item
+ index = i
+ }
+ }
+
+ return max, index
+}
+
+// Latest search the maximum time.Time of a collection.
+// Returns zero value when the collection is empty.
+func Latest(times ...time.Time) time.Time {
+ var max time.Time
+
+ if len(times) == 0 {
+ return max
+ }
+
+ max = times[0]
+
+ for i := 1; i < len(times); i++ {
+ item := times[i]
+
+ if item.After(max) {
+ max = item
+ }
+ }
+
+ return max
+}
+
+// LatestBy search the maximum time.Time of a collection using the given iteratee function.
+// Returns zero value when the collection is empty.
+func LatestBy[T any](collection []T, iteratee func(item T) time.Time) T {
+ var latest T
+
+ if len(collection) == 0 {
+ return latest
+ }
+
+ latest = collection[0]
+ latestTime := iteratee(collection[0])
+
+ for i := 1; i < len(collection); i++ {
+ itemTime := iteratee(collection[i])
+
+ if itemTime.After(latestTime) {
+ latest = collection[i]
+ latestTime = itemTime
+ }
+ }
+
+ return latest
+}
+
+// First returns the first element of a collection and check for availability of the first element.
+func First[T any](collection []T) (T, bool) {
+ length := len(collection)
+
+ if length == 0 {
+ var t T
+ return t, false
+ }
+
+ return collection[0], true
+}
+
+// FirstOrEmpty returns the first element of a collection or zero value if empty.
+func FirstOrEmpty[T any](collection []T) T {
+ i, _ := First(collection)
+ return i
+}
+
+// FirstOr returns the first element of a collection or the fallback value if empty.
+func FirstOr[T any](collection []T, fallback T) T {
+ i, ok := First(collection)
+ if !ok {
+ return fallback
+ }
+
+ return i
+}
+
+// Last returns the last element of a collection or error if empty.
+func Last[T any](collection []T) (T, bool) {
+ length := len(collection)
+
+ if length == 0 {
+ var t T
+ return t, false
+ }
+
+ return collection[length-1], true
+}
+
+// LastOrEmpty returns the last element of a collection or zero value if empty.
+func LastOrEmpty[T any](collection []T) T {
+ i, _ := Last(collection)
+ return i
+}
+
+// LastOr returns the last element of a collection or the fallback value if empty.
+func LastOr[T any](collection []T, fallback T) T {
+ i, ok := Last(collection)
+ if !ok {
+ return fallback
+ }
+
+ return i
+}
+
+// Nth returns the element at index `nth` of collection. If `nth` is negative, the nth element
+// from the end is returned. An error is returned when nth is out of slice bounds.
+func Nth[T any, N constraints.Integer](collection []T, nth N) (T, error) {
+ n := int(nth)
+ l := len(collection)
+ if n >= l || -n > l {
+ var t T
+ return t, fmt.Errorf("nth: %d out of slice bounds", n)
+ }
+
+ if n >= 0 {
+ return collection[n], nil
+ }
+ return collection[l+n], nil
+}
+
+// NthOr returns the element at index `nth` of collection.
+// If `nth` is negative, it returns the nth element from the end.
+// If `nth` is out of slice bounds, it returns the fallback value instead of an error.
+func NthOr[T any, N constraints.Integer](collection []T, nth N, fallback T) T {
+ value, err := Nth(collection, nth)
+ if err != nil {
+ return fallback
+ }
+ return value
+}
+
+// NthOrEmpty returns the element at index `nth` of collection.
+// If `nth` is negative, it returns the nth element from the end.
+// If `nth` is out of slice bounds, it returns the zero value (empty value) for that type.
+func NthOrEmpty[T any, N constraints.Integer](collection []T, nth N) T {
+ value, err := Nth(collection, nth)
+ if err != nil {
+ var zeroValue T
+ return zeroValue
+ }
+ return value
+}
+
+// randomIntGenerator is a function that should return a random integer in the range [0, n)
+// where n is the parameter passed to the randomIntGenerator.
+type randomIntGenerator func(n int) int
+
+// Sample returns a random item from collection.
+func Sample[T any](collection []T) T {
+ result := SampleBy(collection, rand.IntN)
+ return result
+}
+
+// SampleBy returns a random item from collection, using randomIntGenerator as the random index generator.
+func SampleBy[T any](collection []T, randomIntGenerator randomIntGenerator) T {
+ size := len(collection)
+ if size == 0 {
+ return Empty[T]()
+ }
+ return collection[randomIntGenerator(size)]
+}
+
+// Samples returns N random unique items from collection.
+func Samples[T any, Slice ~[]T](collection Slice, count int) Slice {
+ results := SamplesBy(collection, count, rand.IntN)
+ return results
+}
+
+// SamplesBy returns N random unique items from collection, using randomIntGenerator as the random index generator.
+func SamplesBy[T any, Slice ~[]T](collection Slice, count int, randomIntGenerator randomIntGenerator) Slice {
+ size := len(collection)
+
+ copy := append(Slice{}, collection...)
+
+ results := Slice{}
+
+ for i := 0; i < size && i < count; i++ {
+ copyLength := size - i
+
+ index := randomIntGenerator(size - i)
+ results = append(results, copy[index])
+
+ // Removes element.
+ // It is faster to swap with last element and remove it.
+ copy[index] = copy[copyLength-1]
+ copy = copy[:copyLength-1]
+ }
+
+ return results
+}
diff --git a/vendor/github.com/samber/lo/func.go b/vendor/github.com/samber/lo/func.go
new file mode 100644
index 00000000..5fa1cbc8
--- /dev/null
+++ b/vendor/github.com/samber/lo/func.go
@@ -0,0 +1,41 @@
+package lo
+
+// Partial returns new function that, when called, has its first argument set to the provided value.
+func Partial[T1, T2, R any](f func(a T1, b T2) R, arg1 T1) func(T2) R {
+ return func(t2 T2) R {
+ return f(arg1, t2)
+ }
+}
+
+// Partial1 returns new function that, when called, has its first argument set to the provided value.
+func Partial1[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R {
+ return Partial(f, arg1)
+}
+
+// Partial2 returns new function that, when called, has its first argument set to the provided value.
+func Partial2[T1, T2, T3, R any](f func(T1, T2, T3) R, arg1 T1) func(T2, T3) R {
+ return func(t2 T2, t3 T3) R {
+ return f(arg1, t2, t3)
+ }
+}
+
+// Partial3 returns new function that, when called, has its first argument set to the provided value.
+func Partial3[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, arg1 T1) func(T2, T3, T4) R {
+ return func(t2 T2, t3 T3, t4 T4) R {
+ return f(arg1, t2, t3, t4)
+ }
+}
+
+// Partial4 returns new function that, when called, has its first argument set to the provided value.
+func Partial4[T1, T2, T3, T4, T5, R any](f func(T1, T2, T3, T4, T5) R, arg1 T1) func(T2, T3, T4, T5) R {
+ return func(t2 T2, t3 T3, t4 T4, t5 T5) R {
+ return f(arg1, t2, t3, t4, t5)
+ }
+}
+
+// Partial5 returns new function that, when called, has its first argument set to the provided value
+func Partial5[T1, T2, T3, T4, T5, T6, R any](f func(T1, T2, T3, T4, T5, T6) R, arg1 T1) func(T2, T3, T4, T5, T6) R {
+ return func(t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) R {
+ return f(arg1, t2, t3, t4, t5, t6)
+ }
+}
diff --git a/vendor/github.com/samber/lo/internal/constraints/constraints.go b/vendor/github.com/samber/lo/internal/constraints/constraints.go
new file mode 100644
index 00000000..3eb1cda5
--- /dev/null
+++ b/vendor/github.com/samber/lo/internal/constraints/constraints.go
@@ -0,0 +1,42 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package constraints defines a set of useful constraints to be used
+// with type parameters.
+package constraints
+
+// Signed is a constraint that permits any signed integer type.
+// If future releases of Go add new predeclared signed integer types,
+// this constraint will be modified to include them.
+type Signed interface {
+ ~int | ~int8 | ~int16 | ~int32 | ~int64
+}
+
+// Unsigned is a constraint that permits any unsigned integer type.
+// If future releases of Go add new predeclared unsigned integer types,
+// this constraint will be modified to include them.
+type Unsigned interface {
+ ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
+}
+
+// Integer is a constraint that permits any integer type.
+// If future releases of Go add new predeclared integer types,
+// this constraint will be modified to include them.
+type Integer interface {
+ Signed | Unsigned
+}
+
+// Float is a constraint that permits any floating-point type.
+// If future releases of Go add new predeclared floating-point types,
+// this constraint will be modified to include them.
+type Float interface {
+ ~float32 | ~float64
+}
+
+// Complex is a constraint that permits any complex numeric type.
+// If future releases of Go add new predeclared complex numeric types,
+// this constraint will be modified to include them.
+type Complex interface {
+ ~complex64 | ~complex128
+}
diff --git a/vendor/github.com/samber/lo/internal/constraints/ordered_go118.go b/vendor/github.com/samber/lo/internal/constraints/ordered_go118.go
new file mode 100644
index 00000000..a124366f
--- /dev/null
+++ b/vendor/github.com/samber/lo/internal/constraints/ordered_go118.go
@@ -0,0 +1,11 @@
+//go:build !go1.21
+
+package constraints
+
+// Ordered is a constraint that permits any ordered type: any type
+// that supports the operators < <= >= >.
+// If future releases of Go add new ordered types,
+// this constraint will be modified to include them.
+type Ordered interface {
+ Integer | Float | ~string
+}
diff --git a/vendor/github.com/samber/lo/internal/constraints/ordered_go121.go b/vendor/github.com/samber/lo/internal/constraints/ordered_go121.go
new file mode 100644
index 00000000..c02de935
--- /dev/null
+++ b/vendor/github.com/samber/lo/internal/constraints/ordered_go121.go
@@ -0,0 +1,9 @@
+//go:build go1.21
+
+package constraints
+
+import (
+ "cmp"
+)
+
+type Ordered = cmp.Ordered
diff --git a/vendor/github.com/samber/lo/internal/rand/ordered_go118.go b/vendor/github.com/samber/lo/internal/rand/ordered_go118.go
new file mode 100644
index 00000000..9fbc5385
--- /dev/null
+++ b/vendor/github.com/samber/lo/internal/rand/ordered_go118.go
@@ -0,0 +1,26 @@
+//go:build !go1.22
+
+package rand
+
+import "math/rand"
+
+func Shuffle(n int, swap func(i, j int)) {
+ rand.Shuffle(n, swap)
+}
+
+func IntN(n int) int {
+ // bearer:disable go_gosec_crypto_weak_random
+ return rand.Intn(n)
+}
+
+func Int64() int64 {
+ // bearer:disable go_gosec_crypto_weak_random
+ n := rand.Int63()
+
+ // bearer:disable go_gosec_crypto_weak_random
+ if rand.Intn(2) == 0 {
+ return -n
+ }
+
+ return n
+}
diff --git a/vendor/github.com/samber/lo/internal/rand/ordered_go122.go b/vendor/github.com/samber/lo/internal/rand/ordered_go122.go
new file mode 100644
index 00000000..65abf51a
--- /dev/null
+++ b/vendor/github.com/samber/lo/internal/rand/ordered_go122.go
@@ -0,0 +1,17 @@
+//go:build go1.22
+
+package rand
+
+import "math/rand/v2"
+
+func Shuffle(n int, swap func(i, j int)) {
+ rand.Shuffle(n, swap)
+}
+
+func IntN(n int) int {
+ return rand.IntN(n)
+}
+
+func Int64() int64 {
+ return rand.Int64()
+}
diff --git a/vendor/github.com/samber/lo/intersect.go b/vendor/github.com/samber/lo/intersect.go
new file mode 100644
index 00000000..c57bd817
--- /dev/null
+++ b/vendor/github.com/samber/lo/intersect.go
@@ -0,0 +1,265 @@
+package lo
+
+// Contains returns true if an element is present in a collection.
+func Contains[T comparable](collection []T, element T) bool {
+ for i := range collection {
+ if collection[i] == element {
+ return true
+ }
+ }
+
+ return false
+}
+
+// ContainsBy returns true if predicate function return true.
+func ContainsBy[T any](collection []T, predicate func(item T) bool) bool {
+ for i := range collection {
+ if predicate(collection[i]) {
+ return true
+ }
+ }
+
+ return false
+}
+
+// Every returns true if all elements of a subset are contained into a collection or if the subset is empty.
+func Every[T comparable](collection []T, subset []T) bool {
+ for i := range subset {
+ if !Contains(collection, subset[i]) {
+ return false
+ }
+ }
+
+ return true
+}
+
+// EveryBy returns true if the predicate returns true for all elements in the collection or if the collection is empty.
+func EveryBy[T any](collection []T, predicate func(item T) bool) bool {
+ for i := range collection {
+ if !predicate(collection[i]) {
+ return false
+ }
+ }
+
+ return true
+}
+
+// Some returns true if at least 1 element of a subset is contained into a collection.
+// If the subset is empty Some returns false.
+func Some[T comparable](collection []T, subset []T) bool {
+ for i := range subset {
+ if Contains(collection, subset[i]) {
+ return true
+ }
+ }
+
+ return false
+}
+
+// SomeBy returns true if the predicate returns true for any of the elements in the collection.
+// If the collection is empty SomeBy returns false.
+func SomeBy[T any](collection []T, predicate func(item T) bool) bool {
+ for i := range collection {
+ if predicate(collection[i]) {
+ return true
+ }
+ }
+
+ return false
+}
+
+// None returns true if no element of a subset are contained into a collection or if the subset is empty.
+func None[T comparable](collection []T, subset []T) bool {
+ for i := range subset {
+ if Contains(collection, subset[i]) {
+ return false
+ }
+ }
+
+ return true
+}
+
+// NoneBy returns true if the predicate returns true for none of the elements in the collection or if the collection is empty.
+func NoneBy[T any](collection []T, predicate func(item T) bool) bool {
+ for i := range collection {
+ if predicate(collection[i]) {
+ return false
+ }
+ }
+
+ return true
+}
+
+// Intersect returns the intersection between two collections.
+func Intersect[T comparable, Slice ~[]T](list1 Slice, list2 Slice) Slice {
+ result := Slice{}
+ seen := map[T]struct{}{}
+
+ for i := range list1 {
+ seen[list1[i]] = struct{}{}
+ }
+
+ for i := range list2 {
+ if _, ok := seen[list2[i]]; ok {
+ result = append(result, list2[i])
+ }
+ }
+
+ return result
+}
+
+// Difference returns the difference between two collections.
+// The first value is the collection of element absent of list2.
+// The second value is the collection of element absent of list1.
+func Difference[T comparable, Slice ~[]T](list1 Slice, list2 Slice) (Slice, Slice) {
+ left := Slice{}
+ right := Slice{}
+
+ seenLeft := map[T]struct{}{}
+ seenRight := map[T]struct{}{}
+
+ for i := range list1 {
+ seenLeft[list1[i]] = struct{}{}
+ }
+
+ for i := range list2 {
+ seenRight[list2[i]] = struct{}{}
+ }
+
+ for i := range list1 {
+ if _, ok := seenRight[list1[i]]; !ok {
+ left = append(left, list1[i])
+ }
+ }
+
+ for i := range list2 {
+ if _, ok := seenLeft[list2[i]]; !ok {
+ right = append(right, list2[i])
+ }
+ }
+
+ return left, right
+}
+
+// Union returns all distinct elements from given collections.
+// result returns will not change the order of elements relatively.
+func Union[T comparable, Slice ~[]T](lists ...Slice) Slice {
+ var capLen int
+
+ for _, list := range lists {
+ capLen += len(list)
+ }
+
+ result := make(Slice, 0, capLen)
+ seen := make(map[T]struct{}, capLen)
+
+ for i := range lists {
+ for j := range lists[i] {
+ if _, ok := seen[lists[i][j]]; !ok {
+ seen[lists[i][j]] = struct{}{}
+ result = append(result, lists[i][j])
+ }
+ }
+ }
+
+ return result
+}
+
+// Without returns slice excluding all given values.
+func Without[T comparable, Slice ~[]T](collection Slice, exclude ...T) Slice {
+ excludeMap := make(map[T]struct{}, len(exclude))
+ for i := range exclude {
+ excludeMap[exclude[i]] = struct{}{}
+ }
+
+ result := make(Slice, 0, len(collection))
+ for i := range collection {
+ if _, ok := excludeMap[collection[i]]; !ok {
+ result = append(result, collection[i])
+ }
+ }
+ return result
+}
+
+// WithoutBy filters a slice by excluding elements whose extracted keys match any in the exclude list.
+// It returns a new slice containing only the elements whose keys are not in the exclude list.
+func WithoutBy[T any, K comparable](collection []T, iteratee func(item T) K, exclude ...K) []T {
+ excludeMap := make(map[K]struct{}, len(exclude))
+ for _, e := range exclude {
+ excludeMap[e] = struct{}{}
+ }
+
+ result := make([]T, 0, len(collection))
+ for _, item := range collection {
+ if _, ok := excludeMap[iteratee(item)]; !ok {
+ result = append(result, item)
+ }
+ }
+ return result
+}
+
+// WithoutEmpty returns slice excluding zero values.
+//
+// Deprecated: Use lo.Compact instead.
+func WithoutEmpty[T comparable, Slice ~[]T](collection Slice) Slice {
+ return Compact(collection)
+}
+
+// WithoutNth returns slice excluding nth value.
+func WithoutNth[T comparable, Slice ~[]T](collection Slice, nths ...int) Slice {
+ length := len(collection)
+
+ toRemove := make(map[int]struct{}, len(nths))
+ for i := range nths {
+ if nths[i] >= 0 && nths[i] <= length-1 {
+ toRemove[nths[i]] = struct{}{}
+ }
+ }
+
+ result := make(Slice, 0, len(collection))
+ for i := range collection {
+ if _, ok := toRemove[i]; !ok {
+ result = append(result, collection[i])
+ }
+ }
+
+ return result
+}
+
+// ElementsMatch returns true if lists contain the same set of elements (including empty set).
+// If there are duplicate elements, the number of appearances of each of them in both lists should match.
+// The order of elements is not checked.
+func ElementsMatch[T comparable, Slice ~[]T](list1 Slice, list2 Slice) bool {
+ return ElementsMatchBy(list1, list2, func(item T) T { return item })
+}
+
+// ElementsMatchBy returns true if lists contain the same set of elements' keys (including empty set).
+// If there are duplicate keys, the number of appearances of each of them in both lists should match.
+// The order of elements is not checked.
+func ElementsMatchBy[T any, K comparable](list1 []T, list2 []T, iteratee func(item T) K) bool {
+ if len(list1) != len(list2) {
+ return false
+ }
+
+ if len(list1) == 0 {
+ return true
+ }
+
+ counters := make(map[K]int, len(list1))
+
+ for _, el := range list1 {
+ counters[iteratee(el)]++
+ }
+
+ for _, el := range list2 {
+ counters[iteratee(el)]--
+ }
+
+ for _, count := range counters {
+ if count != 0 {
+ return false
+ }
+ }
+
+ return true
+}
diff --git a/vendor/github.com/samber/lo/map.go b/vendor/github.com/samber/lo/map.go
new file mode 100644
index 00000000..6febb3fd
--- /dev/null
+++ b/vendor/github.com/samber/lo/map.go
@@ -0,0 +1,344 @@
+package lo
+
+// Keys creates an array of the map keys.
+// Play: https://go.dev/play/p/Uu11fHASqrU
+func Keys[K comparable, V any](in ...map[K]V) []K {
+ size := 0
+ for i := range in {
+ size += len(in[i])
+ }
+ result := make([]K, 0, size)
+
+ for i := range in {
+ for k := range in[i] {
+ result = append(result, k)
+ }
+ }
+
+ return result
+}
+
+// UniqKeys creates an array of unique keys in the map.
+// Play: https://go.dev/play/p/TPKAb6ILdHk
+func UniqKeys[K comparable, V any](in ...map[K]V) []K {
+ size := 0
+ for i := range in {
+ size += len(in[i])
+ }
+
+ seen := make(map[K]struct{}, size)
+ result := make([]K, 0)
+
+ for i := range in {
+ for k := range in[i] {
+ if _, exists := seen[k]; exists {
+ continue
+ }
+ seen[k] = struct{}{}
+ result = append(result, k)
+ }
+ }
+
+ return result
+}
+
+// HasKey returns whether the given key exists.
+// Play: https://go.dev/play/p/aVwubIvECqS
+func HasKey[K comparable, V any](in map[K]V, key K) bool {
+ _, ok := in[key]
+ return ok
+}
+
+// Values creates an array of the map values.
+// Play: https://go.dev/play/p/nnRTQkzQfF6
+func Values[K comparable, V any](in ...map[K]V) []V {
+ size := 0
+ for i := range in {
+ size += len(in[i])
+ }
+ result := make([]V, 0, size)
+
+ for i := range in {
+ for k := range in[i] {
+ result = append(result, in[i][k])
+ }
+ }
+
+ return result
+}
+
+// UniqValues creates an array of unique values in the map.
+// Play: https://go.dev/play/p/nf6bXMh7rM3
+func UniqValues[K comparable, V comparable](in ...map[K]V) []V {
+ size := 0
+ for i := range in {
+ size += len(in[i])
+ }
+
+ seen := make(map[V]struct{}, size)
+ result := make([]V, 0)
+
+ for i := range in {
+ for k := range in[i] {
+ val := in[i][k]
+ if _, exists := seen[val]; exists {
+ continue
+ }
+ seen[val] = struct{}{}
+ result = append(result, val)
+ }
+ }
+
+ return result
+}
+
+// ValueOr returns the value of the given key or the fallback value if the key is not present.
+// Play: https://go.dev/play/p/bAq9mHErB4V
+func ValueOr[K comparable, V any](in map[K]V, key K, fallback V) V {
+ if v, ok := in[key]; ok {
+ return v
+ }
+ return fallback
+}
+
+// PickBy returns same map type filtered by given predicate.
+// Play: https://go.dev/play/p/kdg8GR_QMmf
+func PickBy[K comparable, V any, Map ~map[K]V](in Map, predicate func(key K, value V) bool) Map {
+ r := Map{}
+ for k := range in {
+ if predicate(k, in[k]) {
+ r[k] = in[k]
+ }
+ }
+ return r
+}
+
+// PickByKeys returns same map type filtered by given keys.
+// Play: https://go.dev/play/p/R1imbuci9qU
+func PickByKeys[K comparable, V any, Map ~map[K]V](in Map, keys []K) Map {
+ r := Map{}
+ for i := range keys {
+ if v, ok := in[keys[i]]; ok {
+ r[keys[i]] = v
+ }
+ }
+ return r
+}
+
+// PickByValues returns same map type filtered by given values.
+// Play: https://go.dev/play/p/1zdzSvbfsJc
+func PickByValues[K comparable, V comparable, Map ~map[K]V](in Map, values []V) Map {
+ r := Map{}
+ for k := range in {
+ if Contains(values, in[k]) {
+ r[k] = in[k]
+ }
+ }
+ return r
+}
+
+// OmitBy returns same map type filtered by given predicate.
+// Play: https://go.dev/play/p/EtBsR43bdsd
+func OmitBy[K comparable, V any, Map ~map[K]V](in Map, predicate func(key K, value V) bool) Map {
+ r := Map{}
+ for k := range in {
+ if !predicate(k, in[k]) {
+ r[k] = in[k]
+ }
+ }
+ return r
+}
+
+// OmitByKeys returns same map type filtered by given keys.
+// Play: https://go.dev/play/p/t1QjCrs-ysk
+func OmitByKeys[K comparable, V any, Map ~map[K]V](in Map, keys []K) Map {
+ r := Map{}
+ for k := range in {
+ r[k] = in[k]
+ }
+ for i := range keys {
+ delete(r, keys[i])
+ }
+ return r
+}
+
+// OmitByValues returns same map type filtered by given values.
+// Play: https://go.dev/play/p/9UYZi-hrs8j
+func OmitByValues[K comparable, V comparable, Map ~map[K]V](in Map, values []V) Map {
+ r := Map{}
+ for k := range in {
+ if !Contains(values, in[k]) {
+ r[k] = in[k]
+ }
+ }
+ return r
+}
+
+// Entries transforms a map into array of key/value pairs.
+// Play:
+func Entries[K comparable, V any](in map[K]V) []Entry[K, V] {
+ entries := make([]Entry[K, V], 0, len(in))
+
+ for k := range in {
+ entries = append(entries, Entry[K, V]{
+ Key: k,
+ Value: in[k],
+ })
+ }
+
+ return entries
+}
+
+// ToPairs transforms a map into array of key/value pairs.
+// Alias of Entries().
+// Play: https://go.dev/play/p/3Dhgx46gawJ
+func ToPairs[K comparable, V any](in map[K]V) []Entry[K, V] {
+ return Entries(in)
+}
+
+// FromEntries transforms an array of key/value pairs into a map.
+// Play: https://go.dev/play/p/oIr5KHFGCEN
+func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V {
+ out := make(map[K]V, len(entries))
+
+ for i := range entries {
+ out[entries[i].Key] = entries[i].Value
+ }
+
+ return out
+}
+
+// FromPairs transforms an array of key/value pairs into a map.
+// Alias of FromEntries().
+// Play: https://go.dev/play/p/oIr5KHFGCEN
+func FromPairs[K comparable, V any](entries []Entry[K, V]) map[K]V {
+ return FromEntries(entries)
+}
+
+// Invert creates a map composed of the inverted keys and values. If map
+// contains duplicate values, subsequent values overwrite property assignments
+// of previous values.
+// Play: https://go.dev/play/p/rFQ4rak6iA1
+func Invert[K comparable, V comparable](in map[K]V) map[V]K {
+ out := make(map[V]K, len(in))
+
+ for k := range in {
+ out[in[k]] = k
+ }
+
+ return out
+}
+
+// Assign merges multiple maps from left to right.
+// Play: https://go.dev/play/p/VhwfJOyxf5o
+func Assign[K comparable, V any, Map ~map[K]V](maps ...Map) Map {
+ count := 0
+ for i := range maps {
+ count += len(maps[i])
+ }
+
+ out := make(Map, count)
+ for i := range maps {
+ for k := range maps[i] {
+ out[k] = maps[i][k]
+ }
+ }
+
+ return out
+}
+
+// ChunkEntries splits a map into an array of elements in groups of a length equal to its size. If the map cannot be split evenly,
+// the final chunk will contain the remaining elements.
+// Play: https://go.dev/play/p/X_YQL6mmoD-
+func ChunkEntries[K comparable, V any](m map[K]V, size int) []map[K]V {
+ if size <= 0 {
+ panic("The chunk size must be greater than 0")
+ }
+
+ count := len(m)
+ if count == 0 {
+ return []map[K]V{}
+ }
+
+ chunksNum := count / size
+ if count%size != 0 {
+ chunksNum += 1
+ }
+
+ result := make([]map[K]V, 0, chunksNum)
+
+ for k, v := range m {
+ if len(result) == 0 || len(result[len(result)-1]) == size {
+ result = append(result, make(map[K]V, size))
+ }
+
+ result[len(result)-1][k] = v
+ }
+
+ return result
+}
+
+// MapKeys manipulates a map keys and transforms it to a map of another type.
+// Play: https://go.dev/play/p/9_4WPIqOetJ
+func MapKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(value V, key K) R) map[R]V {
+ result := make(map[R]V, len(in))
+
+ for k := range in {
+ result[iteratee(in[k], k)] = in[k]
+ }
+
+ return result
+}
+
+// MapValues manipulates a map values and transforms it to a map of another type.
+// Play: https://go.dev/play/p/T_8xAfvcf0W
+func MapValues[K comparable, V any, R any](in map[K]V, iteratee func(value V, key K) R) map[K]R {
+ result := make(map[K]R, len(in))
+
+ for k := range in {
+ result[k] = iteratee(in[k], k)
+ }
+
+ return result
+}
+
+// MapEntries manipulates a map entries and transforms it to a map of another type.
+// Play: https://go.dev/play/p/VuvNQzxKimT
+func MapEntries[K1 comparable, V1 any, K2 comparable, V2 any](in map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2 {
+ result := make(map[K2]V2, len(in))
+
+ for k1 := range in {
+ k2, v2 := iteratee(k1, in[k1])
+ result[k2] = v2
+ }
+
+ return result
+}
+
+// MapToSlice transforms a map into a slice based on specific iteratee
+// Play: https://go.dev/play/p/ZuiCZpDt6LD
+func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R {
+ result := make([]R, 0, len(in))
+
+ for k := range in {
+ result = append(result, iteratee(k, in[k]))
+ }
+
+ return result
+}
+
+// FilterMapToSlice transforms a map into a slice based on specific iteratee.
+// The iteratee returns a value and a boolean. If the boolean is true, the value is added to the result slice.
+// If the boolean is false, the value is not added to the result slice.
+// The order of the keys in the input map is not specified and the order of the keys in the output slice is not guaranteed.
+func FilterMapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) (R, bool)) []R {
+ result := make([]R, 0, len(in))
+
+ for k := range in {
+ if v, ok := iteratee(k, in[k]); ok {
+ result = append(result, v)
+ }
+ }
+
+ return result
+}
diff --git a/vendor/github.com/samber/lo/math.go b/vendor/github.com/samber/lo/math.go
new file mode 100644
index 00000000..e3f42892
--- /dev/null
+++ b/vendor/github.com/samber/lo/math.go
@@ -0,0 +1,142 @@
+package lo
+
+import (
+ "github.com/samber/lo/internal/constraints"
+)
+
+// Range creates an array of numbers (positive and/or negative) with given length.
+// Play: https://go.dev/play/p/0r6VimXAi9H
+func Range(elementNum int) []int {
+ length := If(elementNum < 0, -elementNum).Else(elementNum)
+ result := make([]int, length)
+ step := If(elementNum < 0, -1).Else(1)
+ for i, j := 0, 0; i < length; i, j = i+1, j+step {
+ result[i] = j
+ }
+ return result
+}
+
+// RangeFrom creates an array of numbers from start with specified length.
+// Play: https://go.dev/play/p/0r6VimXAi9H
+func RangeFrom[T constraints.Integer | constraints.Float](start T, elementNum int) []T {
+ length := If(elementNum < 0, -elementNum).Else(elementNum)
+ result := make([]T, length)
+ step := If(elementNum < 0, -1).Else(1)
+ for i, j := 0, start; i < length; i, j = i+1, j+T(step) {
+ result[i] = j
+ }
+ return result
+}
+
+// RangeWithSteps creates an array of numbers (positive and/or negative) progressing from start up to, but not including end.
+// step set to zero will return empty array.
+// Play: https://go.dev/play/p/0r6VimXAi9H
+func RangeWithSteps[T constraints.Integer | constraints.Float](start, end, step T) []T {
+ result := []T{}
+ if start == end || step == 0 {
+ return result
+ }
+ if start < end {
+ if step < 0 {
+ return result
+ }
+ for i := start; i < end; i += step {
+ result = append(result, i)
+ }
+ return result
+ }
+ if step > 0 {
+ return result
+ }
+ for i := start; i > end; i += step {
+ result = append(result, i)
+ }
+ return result
+}
+
+// Clamp clamps number within the inclusive lower and upper bounds.
+// Play: https://go.dev/play/p/RU4lJNC2hlI
+func Clamp[T constraints.Ordered](value T, min T, max T) T {
+ if value < min {
+ return min
+ } else if value > max {
+ return max
+ }
+ return value
+}
+
+// Sum sums the values in a collection. If collection is empty 0 is returned.
+// Play: https://go.dev/play/p/upfeJVqs4Bt
+func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T {
+ var sum T = 0
+ for i := range collection {
+ sum += collection[i]
+ }
+ return sum
+}
+
+// SumBy summarizes the values in a collection using the given return value from the iteration function. If collection is empty 0 is returned.
+// Play: https://go.dev/play/p/Dz_a_7jN_ca
+func SumBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](collection []T, iteratee func(item T) R) R {
+ var sum R = 0
+ for i := range collection {
+ sum = sum + iteratee(collection[i])
+ }
+ return sum
+}
+
+// Product gets the product of the values in a collection. If collection is empty 0 is returned.
+// Play: https://go.dev/play/p/2_kjM_smtAH
+func Product[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T {
+ if collection == nil {
+ return 1
+ }
+
+ if len(collection) == 0 {
+ return 1
+ }
+
+ var product T = 1
+ for i := range collection {
+ product *= collection[i]
+ }
+ return product
+}
+
+// ProductBy summarizes the values in a collection using the given return value from the iteration function. If collection is empty 0 is returned.
+// Play: https://go.dev/play/p/wadzrWr9Aer
+func ProductBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](collection []T, iteratee func(item T) R) R {
+ if collection == nil {
+ return 1
+ }
+
+ if len(collection) == 0 {
+ return 1
+ }
+
+ var product R = 1
+ for i := range collection {
+ product = product * iteratee(collection[i])
+ }
+ return product
+}
+
+// Mean calculates the mean of a collection of numbers.
+func Mean[T constraints.Float | constraints.Integer](collection []T) T {
+ var length = T(len(collection))
+ if length == 0 {
+ return 0
+ }
+ var sum = Sum(collection)
+ return sum / length
+}
+
+// MeanBy calculates the mean of a collection of numbers using the given return value from the iteration function.
+func MeanBy[T any, R constraints.Float | constraints.Integer](collection []T, iteratee func(item T) R) R {
+ var length = R(len(collection))
+ if length == 0 {
+ return 0
+ }
+ var sum = SumBy(collection, iteratee)
+ return sum / length
+}
diff --git a/vendor/github.com/samber/lo/mutable/slice.go b/vendor/github.com/samber/lo/mutable/slice.go
new file mode 100644
index 00000000..969f3995
--- /dev/null
+++ b/vendor/github.com/samber/lo/mutable/slice.go
@@ -0,0 +1,71 @@
+package mutable
+
+import "github.com/samber/lo/internal/rand"
+
+// Filter is a generic function that modifies the input slice in-place to contain only the elements
+// that satisfy the provided predicate function. The predicate function takes an element of the slice and its index,
+// and should return true for elements that should be kept and false for elements that should be removed.
+// The function returns the modified slice, which may be shorter than the original if some elements were removed.
+// Note that the order of elements in the original slice is preserved in the output.
+func Filter[T any, Slice ~[]T](collection Slice, predicate func(item T) bool) Slice {
+ j := 0
+ for _, item := range collection {
+ if predicate(item) {
+ collection[j] = item
+ j++
+ }
+ }
+ return collection[:j]
+}
+
+// FilterI is a generic function that modifies the input slice in-place to contain only the elements
+// that satisfy the provided predicate function. The predicate function takes an element of the slice and its index,
+// and should return true for elements that should be kept and false for elements that should be removed.
+// The function returns the modified slice, which may be shorter than the original if some elements were removed.
+// Note that the order of elements in the original slice is preserved in the output.
+func FilterI[T any, Slice ~[]T](collection Slice, predicate func(item T, index int) bool) Slice {
+ j := 0
+ for i, item := range collection {
+ if predicate(item, i) {
+ collection[j] = item
+ j++
+ }
+ }
+ return collection[:j]
+}
+
+// Map is a generic function that modifies the input slice in-place to contain the result of applying the provided
+// function to each element of the slice. The function returns the modified slice, which has the same length as the original.
+func Map[T any, Slice ~[]T](collection Slice, fn func(item T) T) {
+ for i := range collection {
+ collection[i] = fn(collection[i])
+ }
+}
+
+// MapI is a generic function that modifies the input slice in-place to contain the result of applying the provided
+// function to each element of the slice. The function returns the modified slice, which has the same length as the original.
+func MapI[T any, Slice ~[]T](collection Slice, fn func(item T, index int) T) {
+ for i := range collection {
+ collection[i] = fn(collection[i], i)
+ }
+}
+
+// Shuffle returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm.
+// Play: https://go.dev/play/p/2xb3WdLjeSJ
+func Shuffle[T any, Slice ~[]T](collection Slice) {
+ rand.Shuffle(len(collection), func(i, j int) {
+ collection[i], collection[j] = collection[j], collection[i]
+ })
+}
+
+// Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
+// Play: https://go.dev/play/p/O-M5pmCRgzV
+func Reverse[T any, Slice ~[]T](collection Slice) {
+ length := len(collection)
+ half := length / 2
+
+ for i := 0; i < half; i = i + 1 {
+ j := length - 1 - i
+ collection[i], collection[j] = collection[j], collection[i]
+ }
+}
diff --git a/vendor/github.com/samber/lo/retry.go b/vendor/github.com/samber/lo/retry.go
new file mode 100644
index 00000000..5b9cef3d
--- /dev/null
+++ b/vendor/github.com/samber/lo/retry.go
@@ -0,0 +1,375 @@
+package lo
+
+import (
+ "sync"
+ "time"
+)
+
+type debounce struct {
+ after time.Duration
+ mu *sync.Mutex
+ timer *time.Timer
+ done bool
+ callbacks []func()
+}
+
+func (d *debounce) reset() {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ if d.done {
+ return
+ }
+
+ if d.timer != nil {
+ d.timer.Stop()
+ }
+
+ d.timer = time.AfterFunc(d.after, func() {
+ for i := range d.callbacks {
+ d.callbacks[i]()
+ }
+ })
+}
+
+func (d *debounce) cancel() {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ if d.timer != nil {
+ d.timer.Stop()
+ d.timer = nil
+ }
+
+ d.done = true
+}
+
+// NewDebounce creates a debounced instance that delays invoking functions given until after wait milliseconds have elapsed.
+// Play: https://go.dev/play/p/mz32VMK2nqe
+func NewDebounce(duration time.Duration, f ...func()) (func(), func()) {
+ d := &debounce{
+ after: duration,
+ mu: new(sync.Mutex),
+ timer: nil,
+ done: false,
+ callbacks: f,
+ }
+
+ return func() {
+ d.reset()
+ }, d.cancel
+}
+
+type debounceByItem struct {
+ mu *sync.Mutex
+ timer *time.Timer
+ count int
+}
+
+type debounceBy[T comparable] struct {
+ after time.Duration
+ mu *sync.Mutex
+ items map[T]*debounceByItem
+ callbacks []func(key T, count int)
+}
+
+func (d *debounceBy[T]) reset(key T) {
+ d.mu.Lock()
+ if _, ok := d.items[key]; !ok {
+ d.items[key] = &debounceByItem{
+ mu: new(sync.Mutex),
+ timer: nil,
+ }
+ }
+
+ item := d.items[key]
+
+ d.mu.Unlock()
+
+ item.mu.Lock()
+ defer item.mu.Unlock()
+
+ item.count++
+
+ if item.timer != nil {
+ item.timer.Stop()
+ }
+
+ item.timer = time.AfterFunc(d.after, func() {
+ item.mu.Lock()
+ count := item.count
+ item.count = 0
+ item.mu.Unlock()
+
+ for i := range d.callbacks {
+ d.callbacks[i](key, count)
+ }
+ })
+}
+
+func (d *debounceBy[T]) cancel(key T) {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ if item, ok := d.items[key]; ok {
+ item.mu.Lock()
+
+ if item.timer != nil {
+ item.timer.Stop()
+ item.timer = nil
+ }
+
+ item.mu.Unlock()
+
+ delete(d.items, key)
+ }
+}
+
+// NewDebounceBy creates a debounced instance for each distinct key, that delays invoking functions given until after wait milliseconds have elapsed.
+// Play: https://go.dev/play/p/d3Vpt6pxhY8
+func NewDebounceBy[T comparable](duration time.Duration, f ...func(key T, count int)) (func(key T), func(key T)) {
+ d := &debounceBy[T]{
+ after: duration,
+ mu: new(sync.Mutex),
+ items: map[T]*debounceByItem{},
+ callbacks: f,
+ }
+
+ return func(key T) {
+ d.reset(key)
+ }, d.cancel
+}
+
+// Attempt invokes a function N times until it returns valid output. Returns either the caught error or nil.
+// When the first argument is less than `1`, the function runs until a successful response is returned.
+// Play: https://go.dev/play/p/3ggJZ2ZKcMj
+func Attempt(maxIteration int, f func(index int) error) (int, error) {
+ var err error
+
+ for i := 0; maxIteration <= 0 || i < maxIteration; i++ {
+ // for retries >= 0 {
+ err = f(i)
+ if err == nil {
+ return i + 1, nil
+ }
+ }
+
+ return maxIteration, err
+}
+
+// AttemptWithDelay invokes a function N times until it returns valid output,
+// with a pause between each call. Returns either the caught error or nil.
+// When the first argument is less than `1`, the function runs until a successful
+// response is returned.
+// Play: https://go.dev/play/p/tVs6CygC7m1
+func AttemptWithDelay(maxIteration int, delay time.Duration, f func(index int, duration time.Duration) error) (int, time.Duration, error) {
+ var err error
+
+ start := time.Now()
+
+ for i := 0; maxIteration <= 0 || i < maxIteration; i++ {
+ err = f(i, time.Since(start))
+ if err == nil {
+ return i + 1, time.Since(start), nil
+ }
+
+ if maxIteration <= 0 || i+1 < maxIteration {
+ time.Sleep(delay)
+ }
+ }
+
+ return maxIteration, time.Since(start), err
+}
+
+// AttemptWhile invokes a function N times until it returns valid output.
+// Returns either the caught error or nil, along with a bool value to determine
+// whether the function should be invoked again. It will terminate the invoke
+// immediately if the second return value is false. When the first
+// argument is less than `1`, the function runs until a successful response is
+// returned.
+func AttemptWhile(maxIteration int, f func(int) (error, bool)) (int, error) {
+ var err error
+ var shouldContinueInvoke bool
+
+ for i := 0; maxIteration <= 0 || i < maxIteration; i++ {
+ // for retries >= 0 {
+ err, shouldContinueInvoke = f(i)
+ if !shouldContinueInvoke { // if shouldContinueInvoke is false, then return immediately
+ return i + 1, err
+ }
+ if err == nil {
+ return i + 1, nil
+ }
+ }
+
+ return maxIteration, err
+}
+
+// AttemptWhileWithDelay invokes a function N times until it returns valid output,
+// with a pause between each call. Returns either the caught error or nil, along
+// with a bool value to determine whether the function should be invoked again.
+// It will terminate the invoke immediately if the second return value is false.
+// When the first argument is less than `1`, the function runs until a successful
+// response is returned.
+func AttemptWhileWithDelay(maxIteration int, delay time.Duration, f func(int, time.Duration) (error, bool)) (int, time.Duration, error) {
+ var err error
+ var shouldContinueInvoke bool
+
+ start := time.Now()
+
+ for i := 0; maxIteration <= 0 || i < maxIteration; i++ {
+ err, shouldContinueInvoke = f(i, time.Since(start))
+ if !shouldContinueInvoke { // if shouldContinueInvoke is false, then return immediately
+ return i + 1, time.Since(start), err
+ }
+ if err == nil {
+ return i + 1, time.Since(start), nil
+ }
+
+ if maxIteration <= 0 || i+1 < maxIteration {
+ time.Sleep(delay)
+ }
+ }
+
+ return maxIteration, time.Since(start), err
+}
+
+type transactionStep[T any] struct {
+ exec func(T) (T, error)
+ onRollback func(T) T
+}
+
+// NewTransaction instantiate a new transaction.
+func NewTransaction[T any]() *Transaction[T] {
+ return &Transaction[T]{
+ steps: []transactionStep[T]{},
+ }
+}
+
+// Transaction implements a Saga pattern
+type Transaction[T any] struct {
+ steps []transactionStep[T]
+}
+
+// Then adds a step to the chain of callbacks. It returns the same Transaction.
+func (t *Transaction[T]) Then(exec func(T) (T, error), onRollback func(T) T) *Transaction[T] {
+ t.steps = append(t.steps, transactionStep[T]{
+ exec: exec,
+ onRollback: onRollback,
+ })
+
+ return t
+}
+
+// Process runs the Transaction steps and rollbacks in case of errors.
+func (t *Transaction[T]) Process(state T) (T, error) {
+ var i int
+ var err error
+
+ for i < len(t.steps) {
+ state, err = t.steps[i].exec(state)
+ if err != nil {
+ break
+ }
+
+ i++
+ }
+
+ if err == nil {
+ return state, nil
+ }
+
+ for i > 0 {
+ i--
+ state = t.steps[i].onRollback(state)
+ }
+
+ return state, err
+}
+
+// @TODO: single mutex per key ?
+type throttleBy[T comparable] struct {
+ mu *sync.Mutex
+ timer *time.Timer
+ interval time.Duration
+ callbacks []func(key T)
+ countLimit int
+ count map[T]int
+}
+
+func (th *throttleBy[T]) throttledFunc(key T) {
+ th.mu.Lock()
+ defer th.mu.Unlock()
+
+ if _, ok := th.count[key]; !ok {
+ th.count[key] = 0
+ }
+
+ if th.count[key] < th.countLimit {
+ th.count[key]++
+
+ for _, f := range th.callbacks {
+ f(key)
+ }
+
+ }
+ if th.timer == nil {
+ th.timer = time.AfterFunc(th.interval, func() {
+ th.reset()
+ })
+ }
+}
+
+func (th *throttleBy[T]) reset() {
+ th.mu.Lock()
+ defer th.mu.Unlock()
+
+ if th.timer != nil {
+ th.timer.Stop()
+ }
+
+ th.count = map[T]int{}
+ th.timer = nil
+}
+
+// NewThrottle creates a throttled instance that invokes given functions only once in every interval.
+// This returns 2 functions, First one is throttled function and Second one is a function to reset interval
+func NewThrottle(interval time.Duration, f ...func()) (throttle func(), reset func()) {
+ return NewThrottleWithCount(interval, 1, f...)
+}
+
+// NewThrottleWithCount is NewThrottle with count limit, throttled function will be invoked count times in every interval.
+func NewThrottleWithCount(interval time.Duration, count int, f ...func()) (throttle func(), reset func()) {
+ callbacks := Map(f, func(item func(), _ int) func(struct{}) {
+ return func(struct{}) {
+ item()
+ }
+ })
+
+ throttleFn, reset := NewThrottleByWithCount[struct{}](interval, count, callbacks...)
+ return func() {
+ throttleFn(struct{}{})
+ }, reset
+}
+
+// NewThrottleBy creates a throttled instance that invokes given functions only once in every interval.
+// This returns 2 functions, First one is throttled function and Second one is a function to reset interval
+func NewThrottleBy[T comparable](interval time.Duration, f ...func(key T)) (throttle func(key T), reset func()) {
+ return NewThrottleByWithCount[T](interval, 1, f...)
+}
+
+// NewThrottleByWithCount is NewThrottleBy with count limit, throttled function will be invoked count times in every interval.
+func NewThrottleByWithCount[T comparable](interval time.Duration, count int, f ...func(key T)) (throttle func(key T), reset func()) {
+ if count <= 0 {
+ count = 1
+ }
+
+ th := &throttleBy[T]{
+ mu: new(sync.Mutex),
+ interval: interval,
+ callbacks: f,
+ countLimit: count,
+ count: map[T]int{},
+ }
+ return th.throttledFunc, th.reset
+}
diff --git a/vendor/github.com/samber/lo/slice.go b/vendor/github.com/samber/lo/slice.go
new file mode 100644
index 00000000..9c15a6cb
--- /dev/null
+++ b/vendor/github.com/samber/lo/slice.go
@@ -0,0 +1,745 @@
+package lo
+
+import (
+ "sort"
+
+ "github.com/samber/lo/internal/constraints"
+ "github.com/samber/lo/mutable"
+)
+
+// Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for.
+// Play: https://go.dev/play/p/Apjg3WeSi7K
+func Filter[T any, Slice ~[]T](collection Slice, predicate func(item T, index int) bool) Slice {
+ result := make(Slice, 0, len(collection))
+
+ for i := range collection {
+ if predicate(collection[i], i) {
+ result = append(result, collection[i])
+ }
+ }
+
+ return result
+}
+
+// Map manipulates a slice and transforms it to a slice of another type.
+// Play: https://go.dev/play/p/OkPcYAhBo0D
+func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R {
+ result := make([]R, len(collection))
+
+ for i := range collection {
+ result[i] = iteratee(collection[i], i)
+ }
+
+ return result
+}
+
+// UniqMap manipulates a slice and transforms it to a slice of another type with unique values.
+func UniqMap[T any, R comparable](collection []T, iteratee func(item T, index int) R) []R {
+ result := make([]R, 0, len(collection))
+ seen := make(map[R]struct{}, len(collection))
+
+ for i := range collection {
+ r := iteratee(collection[i], i)
+ if _, ok := seen[r]; !ok {
+ result = append(result, r)
+ seen[r] = struct{}{}
+ }
+ }
+ return result
+}
+
+// FilterMap returns a slice which obtained after both filtering and mapping using the given callback function.
+// The callback function should return two values:
+// - the result of the mapping operation and
+// - whether the result element should be included or not.
+//
+// Play: https://go.dev/play/p/-AuYXfy7opz
+func FilterMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R {
+ result := make([]R, 0, len(collection))
+
+ for i := range collection {
+ if r, ok := callback(collection[i], i); ok {
+ result = append(result, r)
+ }
+ }
+
+ return result
+}
+
+// FlatMap manipulates a slice and transforms and flattens it to a slice of another type.
+// The transform function can either return a slice or a `nil`, and in the `nil` case
+// no value is added to the final slice.
+// Play: https://go.dev/play/p/YSoYmQTA8-U
+func FlatMap[T any, R any](collection []T, iteratee func(item T, index int) []R) []R {
+ result := make([]R, 0, len(collection))
+
+ for i := range collection {
+ result = append(result, iteratee(collection[i], i)...)
+ }
+
+ return result
+}
+
+// Reduce reduces collection to a value which is the accumulated result of running each element in collection
+// through accumulator, where each successive invocation is supplied the return value of the previous.
+// Play: https://go.dev/play/p/R4UHXZNaaUG
+func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R {
+ for i := range collection {
+ initial = accumulator(initial, collection[i], i)
+ }
+
+ return initial
+}
+
+// ReduceRight helper is like Reduce except that it iterates over elements of collection from right to left.
+// Play: https://go.dev/play/p/Fq3W70l7wXF
+func ReduceRight[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R {
+ for i := len(collection) - 1; i >= 0; i-- {
+ initial = accumulator(initial, collection[i], i)
+ }
+
+ return initial
+}
+
+// ForEach iterates over elements of collection and invokes iteratee for each element.
+// Play: https://go.dev/play/p/oofyiUPRf8t
+func ForEach[T any](collection []T, iteratee func(item T, index int)) {
+ for i := range collection {
+ iteratee(collection[i], i)
+ }
+}
+
+// ForEachWhile iterates over elements of collection and invokes iteratee for each element
+// collection return value decide to continue or break, like do while().
+// Play: https://go.dev/play/p/QnLGt35tnow
+func ForEachWhile[T any](collection []T, iteratee func(item T, index int) (goon bool)) {
+ for i := range collection {
+ if !iteratee(collection[i], i) {
+ break
+ }
+ }
+}
+
+// Times invokes the iteratee n times, returning an array of the results of each invocation.
+// The iteratee is invoked with index as argument.
+// Play: https://go.dev/play/p/vgQj3Glr6lT
+func Times[T any](count int, iteratee func(index int) T) []T {
+ result := make([]T, count)
+
+ for i := 0; i < count; i++ {
+ result[i] = iteratee(i)
+ }
+
+ return result
+}
+
+// Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept.
+// The order of result values is determined by the order they occur in the array.
+// Play: https://go.dev/play/p/DTzbeXZ6iEN
+func Uniq[T comparable, Slice ~[]T](collection Slice) Slice {
+ result := make(Slice, 0, len(collection))
+ seen := make(map[T]struct{}, len(collection))
+
+ for i := range collection {
+ if _, ok := seen[collection[i]]; ok {
+ continue
+ }
+
+ seen[collection[i]] = struct{}{}
+ result = append(result, collection[i])
+ }
+
+ return result
+}
+
+// UniqBy returns a duplicate-free version of an array, in which only the first occurrence of each element is kept.
+// The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is
+// invoked for each element in array to generate the criterion by which uniqueness is computed.
+// Play: https://go.dev/play/p/g42Z3QSb53u
+func UniqBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) Slice {
+ result := make(Slice, 0, len(collection))
+ seen := make(map[U]struct{}, len(collection))
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ if _, ok := seen[key]; ok {
+ continue
+ }
+
+ seen[key] = struct{}{}
+ result = append(result, collection[i])
+ }
+
+ return result
+}
+
+// GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
+// Play: https://go.dev/play/p/XnQBd_v6brd
+func GroupBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) map[U]Slice {
+ result := map[U]Slice{}
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ result[key] = append(result[key], collection[i])
+ }
+
+ return result
+}
+
+// GroupByMap returns an object composed of keys generated from the results of running each element of collection through iteratee.
+func GroupByMap[T any, K comparable, V any](collection []T, iteratee func(item T) (K, V)) map[K][]V {
+ result := map[K][]V{}
+
+ for i := range collection {
+ k, v := iteratee(collection[i])
+
+ result[k] = append(result[k], v)
+ }
+
+ return result
+}
+
+// Chunk returns an array of elements split into groups the length of size. If array can't be split evenly,
+// the final chunk will be the remaining elements.
+// Play: https://go.dev/play/p/EeKl0AuTehH
+func Chunk[T any, Slice ~[]T](collection Slice, size int) []Slice {
+ if size <= 0 {
+ panic("Second parameter must be greater than 0")
+ }
+
+ chunksNum := len(collection) / size
+ if len(collection)%size != 0 {
+ chunksNum += 1
+ }
+
+ result := make([]Slice, 0, chunksNum)
+
+ for i := 0; i < chunksNum; i++ {
+ last := (i + 1) * size
+ if last > len(collection) {
+ last = len(collection)
+ }
+ result = append(result, collection[i*size:last:last])
+ }
+
+ return result
+}
+
+// PartitionBy returns an array of elements split into groups. The order of grouped values is
+// determined by the order they occur in collection. The grouping is generated from the results
+// of running each element of collection through iteratee.
+// Play: https://go.dev/play/p/NfQ_nGjkgXW
+func PartitionBy[T any, K comparable, Slice ~[]T](collection Slice, iteratee func(item T) K) []Slice {
+ result := []Slice{}
+ seen := map[K]int{}
+
+ for i := range collection {
+ key := iteratee(collection[i])
+
+ resultIndex, ok := seen[key]
+ if !ok {
+ resultIndex = len(result)
+ seen[key] = resultIndex
+ result = append(result, Slice{})
+ }
+
+ result[resultIndex] = append(result[resultIndex], collection[i])
+ }
+
+ return result
+
+ // unordered:
+ // groups := GroupBy[T, K](collection, iteratee)
+ // return Values[K, []T](groups)
+}
+
+// Flatten returns an array a single level deep.
+// Play: https://go.dev/play/p/rbp9ORaMpjw
+func Flatten[T any, Slice ~[]T](collection []Slice) Slice {
+ totalLen := 0
+ for i := range collection {
+ totalLen += len(collection[i])
+ }
+
+ result := make(Slice, 0, totalLen)
+ for i := range collection {
+ result = append(result, collection[i]...)
+ }
+
+ return result
+}
+
+// Interleave round-robin alternating input slices and sequentially appending value at index into result
+// Play: https://go.dev/play/p/-RJkTLQEDVt
+func Interleave[T any, Slice ~[]T](collections ...Slice) Slice {
+ if len(collections) == 0 {
+ return Slice{}
+ }
+
+ maxSize := 0
+ totalSize := 0
+ for i := range collections {
+ size := len(collections[i])
+ totalSize += size
+ if size > maxSize {
+ maxSize = size
+ }
+ }
+
+ if maxSize == 0 {
+ return Slice{}
+ }
+
+ result := make(Slice, totalSize)
+
+ resultIdx := 0
+ for i := 0; i < maxSize; i++ {
+ for j := range collections {
+ if len(collections[j])-1 < i {
+ continue
+ }
+
+ result[resultIdx] = collections[j][i]
+ resultIdx++
+ }
+ }
+
+ return result
+}
+
+// Shuffle returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm.
+// Play: https://go.dev/play/p/ZTGG7OUCdnp
+//
+// Deprecated: use mutable.Shuffle() instead.
+func Shuffle[T any, Slice ~[]T](collection Slice) Slice {
+ mutable.Shuffle(collection)
+ return collection
+}
+
+// Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
+// Play: https://go.dev/play/p/iv2e9jslfBM
+//
+// Deprecated: use mutable.Reverse() instead.
+func Reverse[T any, Slice ~[]T](collection Slice) Slice {
+ mutable.Reverse(collection)
+ return collection
+}
+
+// Fill fills elements of array with `initial` value.
+// Play: https://go.dev/play/p/VwR34GzqEub
+func Fill[T Clonable[T], Slice ~[]T](collection Slice, initial T) Slice {
+ result := make(Slice, 0, len(collection))
+
+ for range collection {
+ result = append(result, initial.Clone())
+ }
+
+ return result
+}
+
+// Repeat builds a slice with N copies of initial value.
+// Play: https://go.dev/play/p/g3uHXbmc3b6
+func Repeat[T Clonable[T]](count int, initial T) []T {
+ result := make([]T, 0, count)
+
+ for i := 0; i < count; i++ {
+ result = append(result, initial.Clone())
+ }
+
+ return result
+}
+
+// RepeatBy builds a slice with values returned by N calls of callback.
+// Play: https://go.dev/play/p/ozZLCtX_hNU
+func RepeatBy[T any](count int, predicate func(index int) T) []T {
+ result := make([]T, 0, count)
+
+ for i := 0; i < count; i++ {
+ result = append(result, predicate(i))
+ }
+
+ return result
+}
+
+// KeyBy transforms a slice or an array of structs to a map based on a pivot callback.
+// Play: https://go.dev/play/p/mdaClUAT-zZ
+func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V {
+ result := make(map[K]V, len(collection))
+
+ for i := range collection {
+ k := iteratee(collection[i])
+ result[k] = collection[i]
+ }
+
+ return result
+}
+
+// Associate returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
+// If any of two pairs would have the same key the last one gets added to the map.
+// The order of keys in returned map is not specified and is not guaranteed to be the same from the original array.
+// Play: https://go.dev/play/p/WHa2CfMO3Lr
+func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V {
+ result := make(map[K]V, len(collection))
+
+ for i := range collection {
+ k, v := transform(collection[i])
+ result[k] = v
+ }
+
+ return result
+}
+
+// SliceToMap returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
+// If any of two pairs would have the same key the last one gets added to the map.
+// The order of keys in returned map is not specified and is not guaranteed to be the same from the original array.
+// Alias of Associate().
+// Play: https://go.dev/play/p/WHa2CfMO3Lr
+func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V {
+ return Associate(collection, transform)
+}
+
+// FilterSliceToMap returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
+// If any of two pairs would have the same key the last one gets added to the map.
+// The order of keys in returned map is not specified and is not guaranteed to be the same from the original array.
+// The third return value of the transform function is a boolean that indicates whether the key-value pair should be included in the map.
+func FilterSliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V, bool)) map[K]V {
+ result := make(map[K]V, len(collection))
+
+ for i := range collection {
+ k, v, ok := transform(collection[i])
+ if ok {
+ result[k] = v
+ }
+ }
+
+ return result
+}
+
+// Keyify returns a map with each unique element of the slice as a key.
+func Keyify[T comparable, Slice ~[]T](collection Slice) map[T]struct{} {
+ result := make(map[T]struct{}, len(collection))
+
+ for i := range collection {
+ result[collection[i]] = struct{}{}
+ }
+
+ return result
+}
+
+// Drop drops n elements from the beginning of a slice or array.
+// Play: https://go.dev/play/p/JswS7vXRJP2
+func Drop[T any, Slice ~[]T](collection Slice, n int) Slice {
+ if len(collection) <= n {
+ return make(Slice, 0)
+ }
+
+ result := make(Slice, 0, len(collection)-n)
+
+ return append(result, collection[n:]...)
+}
+
+// DropRight drops n elements from the end of a slice or array.
+// Play: https://go.dev/play/p/GG0nXkSJJa3
+func DropRight[T any, Slice ~[]T](collection Slice, n int) Slice {
+ if len(collection) <= n {
+ return Slice{}
+ }
+
+ result := make(Slice, 0, len(collection)-n)
+ return append(result, collection[:len(collection)-n]...)
+}
+
+// DropWhile drops elements from the beginning of a slice or array while the predicate returns true.
+// Play: https://go.dev/play/p/7gBPYw2IK16
+func DropWhile[T any, Slice ~[]T](collection Slice, predicate func(item T) bool) Slice {
+ i := 0
+ for ; i < len(collection); i++ {
+ if !predicate(collection[i]) {
+ break
+ }
+ }
+
+ result := make(Slice, 0, len(collection)-i)
+ return append(result, collection[i:]...)
+}
+
+// DropRightWhile drops elements from the end of a slice or array while the predicate returns true.
+// Play: https://go.dev/play/p/3-n71oEC0Hz
+func DropRightWhile[T any, Slice ~[]T](collection Slice, predicate func(item T) bool) Slice {
+ i := len(collection) - 1
+ for ; i >= 0; i-- {
+ if !predicate(collection[i]) {
+ break
+ }
+ }
+
+ result := make(Slice, 0, i+1)
+ return append(result, collection[:i+1]...)
+}
+
+// DropByIndex drops elements from a slice or array by the index.
+// A negative index will drop elements from the end of the slice.
+// Play: https://go.dev/play/p/bPIH4npZRxS
+func DropByIndex[T any](collection []T, indexes ...int) []T {
+ initialSize := len(collection)
+ if initialSize == 0 {
+ return make([]T, 0)
+ }
+
+ for i := range indexes {
+ if indexes[i] < 0 {
+ indexes[i] = initialSize + indexes[i]
+ }
+ }
+
+ indexes = Uniq(indexes)
+ sort.Ints(indexes)
+
+ result := make([]T, 0, initialSize)
+ result = append(result, collection...)
+
+ for i := range indexes {
+ if indexes[i]-i < 0 || indexes[i]-i >= initialSize-i {
+ continue
+ }
+
+ result = append(result[:indexes[i]-i], result[indexes[i]-i+1:]...)
+ }
+
+ return result
+}
+
+// Reject is the opposite of Filter, this method returns the elements of collection that predicate does not return truthy for.
+// Play: https://go.dev/play/p/YkLMODy1WEL
+func Reject[T any, Slice ~[]T](collection Slice, predicate func(item T, index int) bool) Slice {
+ result := Slice{}
+
+ for i := range collection {
+ if !predicate(collection[i], i) {
+ result = append(result, collection[i])
+ }
+ }
+
+ return result
+}
+
+// RejectMap is the opposite of FilterMap, this method returns a slice which obtained after both filtering and mapping using the given callback function.
+// The callback function should return two values:
+// - the result of the mapping operation and
+// - whether the result element should be included or not.
+func RejectMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R {
+ result := []R{}
+
+ for i := range collection {
+ if r, ok := callback(collection[i], i); !ok {
+ result = append(result, r)
+ }
+ }
+
+ return result
+}
+
+// FilterReject mixes Filter and Reject, this method returns two slices, one for the elements of collection that
+// predicate returns truthy for and one for the elements that predicate does not return truthy for.
+func FilterReject[T any, Slice ~[]T](collection Slice, predicate func(T, int) bool) (kept Slice, rejected Slice) {
+ kept = make(Slice, 0, len(collection))
+ rejected = make(Slice, 0, len(collection))
+
+ for i := range collection {
+ if predicate(collection[i], i) {
+ kept = append(kept, collection[i])
+ } else {
+ rejected = append(rejected, collection[i])
+ }
+ }
+
+ return kept, rejected
+}
+
+// Count counts the number of elements in the collection that compare equal to value.
+// Play: https://go.dev/play/p/Y3FlK54yveC
+func Count[T comparable](collection []T, value T) (count int) {
+ for i := range collection {
+ if collection[i] == value {
+ count++
+ }
+ }
+
+ return count
+}
+
+// CountBy counts the number of elements in the collection for which predicate is true.
+// Play: https://go.dev/play/p/ByQbNYQQi4X
+func CountBy[T any](collection []T, predicate func(item T) bool) (count int) {
+ for i := range collection {
+ if predicate(collection[i]) {
+ count++
+ }
+ }
+
+ return count
+}
+
+// CountValues counts the number of each element in the collection.
+// Play: https://go.dev/play/p/-p-PyLT4dfy
+func CountValues[T comparable](collection []T) map[T]int {
+ result := make(map[T]int)
+
+ for i := range collection {
+ result[collection[i]]++
+ }
+
+ return result
+}
+
+// CountValuesBy counts the number of each element return from mapper function.
+// Is equivalent to chaining lo.Map and lo.CountValues.
+// Play: https://go.dev/play/p/2U0dG1SnOmS
+func CountValuesBy[T any, U comparable](collection []T, mapper func(item T) U) map[U]int {
+ result := make(map[U]int)
+
+ for i := range collection {
+ result[mapper(collection[i])]++
+ }
+
+ return result
+}
+
+// Subset returns a copy of a slice from `offset` up to `length` elements. Like `slice[start:start+length]`, but does not panic on overflow.
+// Play: https://go.dev/play/p/tOQu1GhFcog
+func Subset[T any, Slice ~[]T](collection Slice, offset int, length uint) Slice {
+ size := len(collection)
+
+ if offset < 0 {
+ offset = size + offset
+ if offset < 0 {
+ offset = 0
+ }
+ }
+
+ if offset > size {
+ return Slice{}
+ }
+
+ if length > uint(size)-uint(offset) {
+ length = uint(size - offset)
+ }
+
+ return collection[offset : offset+int(length)]
+}
+
+// Slice returns a copy of a slice from `start` up to, but not including `end`. Like `slice[start:end]`, but does not panic on overflow.
+// Play: https://go.dev/play/p/8XWYhfMMA1h
+func Slice[T any, Slice ~[]T](collection Slice, start int, end int) Slice {
+ size := len(collection)
+
+ if start >= end {
+ return Slice{}
+ }
+
+ if start > size {
+ start = size
+ }
+ if start < 0 {
+ start = 0
+ }
+
+ if end > size {
+ end = size
+ }
+ if end < 0 {
+ end = 0
+ }
+
+ return collection[start:end]
+}
+
+// Replace returns a copy of the slice with the first n non-overlapping instances of old replaced by new.
+// Play: https://go.dev/play/p/XfPzmf9gql6
+func Replace[T comparable, Slice ~[]T](collection Slice, old T, new T, n int) Slice {
+ result := make(Slice, len(collection))
+ copy(result, collection)
+
+ for i := range result {
+ if result[i] == old && n != 0 {
+ result[i] = new
+ n--
+ }
+ }
+
+ return result
+}
+
+// ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new.
+// Play: https://go.dev/play/p/a9xZFUHfYcV
+func ReplaceAll[T comparable, Slice ~[]T](collection Slice, old T, new T) Slice {
+ return Replace(collection, old, new, -1)
+}
+
+// Compact returns a slice of all non-zero elements.
+// Play: https://go.dev/play/p/tXiy-iK6PAc
+func Compact[T comparable, Slice ~[]T](collection Slice) Slice {
+ var zero T
+
+ result := make(Slice, 0, len(collection))
+
+ for i := range collection {
+ if collection[i] != zero {
+ result = append(result, collection[i])
+ }
+ }
+
+ return result
+}
+
+// IsSorted checks if a slice is sorted.
+// Play: https://go.dev/play/p/mc3qR-t4mcx
+func IsSorted[T constraints.Ordered](collection []T) bool {
+ for i := 1; i < len(collection); i++ {
+ if collection[i-1] > collection[i] {
+ return false
+ }
+ }
+
+ return true
+}
+
+// IsSortedByKey checks if a slice is sorted by iteratee.
+// Play: https://go.dev/play/p/wiG6XyBBu49
+func IsSortedByKey[T any, K constraints.Ordered](collection []T, iteratee func(item T) K) bool {
+ size := len(collection)
+
+ for i := 0; i < size-1; i++ {
+ if iteratee(collection[i]) > iteratee(collection[i+1]) {
+ return false
+ }
+ }
+
+ return true
+}
+
+// Splice inserts multiple elements at index i. A negative index counts back
+// from the end of the slice. The helper is protected against overflow errors.
+// Play: https://go.dev/play/p/G5_GhkeSUBA
+func Splice[T any, Slice ~[]T](collection Slice, i int, elements ...T) Slice {
+ sizeCollection := len(collection)
+ sizeElements := len(elements)
+ output := make(Slice, 0, sizeCollection+sizeElements) // preallocate memory for the output slice
+
+ if sizeElements == 0 {
+ return append(output, collection...) // simple copy
+ } else if i > sizeCollection {
+ // positive overflow
+ return append(append(output, collection...), elements...)
+ } else if i < -sizeCollection {
+ // negative overflow
+ return append(append(output, elements...), collection...)
+ } else if i < 0 {
+ // backward
+ i = sizeCollection + i
+ }
+
+ return append(append(append(output, collection[:i]...), elements...), collection[i:]...)
+}
diff --git a/vendor/github.com/samber/lo/string.go b/vendor/github.com/samber/lo/string.go
new file mode 100644
index 00000000..923faa32
--- /dev/null
+++ b/vendor/github.com/samber/lo/string.go
@@ -0,0 +1,234 @@
+package lo
+
+import (
+ "math"
+ "regexp"
+ "strings"
+ "unicode"
+ "unicode/utf8"
+
+ "github.com/samber/lo/internal/rand"
+
+ "golang.org/x/text/cases"
+ "golang.org/x/text/language"
+)
+
+var (
+ LowerCaseLettersCharset = []rune("abcdefghijklmnopqrstuvwxyz")
+ UpperCaseLettersCharset = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ LettersCharset = append(LowerCaseLettersCharset, UpperCaseLettersCharset...)
+ NumbersCharset = []rune("0123456789")
+ AlphanumericCharset = append(LettersCharset, NumbersCharset...)
+ SpecialCharset = []rune("!@#$%^&*()_+-=[]{}|;':\",./<>?")
+ AllCharset = append(AlphanumericCharset, SpecialCharset...)
+
+ // bearer:disable go_lang_permissive_regex_validation
+ splitWordReg = regexp.MustCompile(`([a-z])([A-Z0-9])|([a-zA-Z])([0-9])|([0-9])([a-zA-Z])|([A-Z])([A-Z])([a-z])`)
+ // bearer:disable go_lang_permissive_regex_validation
+ splitNumberLetterReg = regexp.MustCompile(`([0-9])([a-zA-Z])`)
+ maximumCapacity = math.MaxInt>>1 + 1
+)
+
+// RandomString return a random string.
+// Play: https://go.dev/play/p/rRseOQVVum4
+func RandomString(size int, charset []rune) string {
+ if size <= 0 {
+ panic("lo.RandomString: Size parameter must be greater than 0")
+ }
+ if len(charset) <= 0 {
+ panic("lo.RandomString: Charset parameter must not be empty")
+ }
+
+ // see https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
+ sb := strings.Builder{}
+ sb.Grow(size)
+ // Calculate the number of bits required to represent the charset,
+ // e.g., for 62 characters, it would need 6 bits (since 62 -> 64 = 2^6)
+ letterIdBits := int(math.Log2(float64(nearestPowerOfTwo(len(charset)))))
+ // Determine the corresponding bitmask,
+ // e.g., for 62 characters, the bitmask would be 111111.
+ var letterIdMask int64 = 1<<letterIdBits - 1
+ // Available count, since rand.Int64() returns a non-negative number, the first bit is fixed, so there are 63 random bits
+ // e.g., for 62 characters, this value is 10 (63 / 6).
+ letterIdMax := 63 / letterIdBits
+ // Generate the random string in a loop.
+ for i, cache, remain := size-1, rand.Int64(), letterIdMax; i >= 0; {
+ // Regenerate the random number if all available bits have been used
+ if remain == 0 {
+ cache, remain = rand.Int64(), letterIdMax
+ }
+ // Select a character from the charset
+ if idx := int(cache & letterIdMask); idx < len(charset) {
+ sb.WriteRune(charset[idx])
+ i--
+ }
+ // Shift the bits to the right to prepare for the next character selection,
+ // e.g., for 62 characters, shift by 6 bits.
+ cache >>= letterIdBits
+ // Decrease the remaining number of uses for the current random number.
+ remain--
+ }
+ return sb.String()
+}
+
+// nearestPowerOfTwo returns the nearest power of two.
+func nearestPowerOfTwo(cap int) int {
+ n := cap - 1
+ n |= n >> 1
+ n |= n >> 2
+ n |= n >> 4
+ n |= n >> 8
+ n |= n >> 16
+ if n < 0 {
+ return 1
+ }
+ if n >= maximumCapacity {
+ return maximumCapacity
+ }
+ return n + 1
+}
+
+// Substring return part of a string.
+// Play: https://go.dev/play/p/TQlxQi82Lu1
+func Substring[T ~string](str T, offset int, length uint) T {
+ rs := []rune(str)
+ size := len(rs)
+
+ if offset < 0 {
+ offset = size + offset
+ if offset < 0 {
+ offset = 0
+ }
+ }
+
+ if offset >= size {
+ return Empty[T]()
+ }
+
+ if length > uint(size)-uint(offset) {
+ length = uint(size - offset)
+ }
+
+ return T(strings.ReplaceAll(string(rs[offset:offset+int(length)]), "\x00", ""))
+}
+
+// ChunkString returns an array of strings split into groups the length of size. If array can't be split evenly,
+// the final chunk will be the remaining elements.
+// Play: https://go.dev/play/p/__FLTuJVz54
+func ChunkString[T ~string](str T, size int) []T {
+ if size <= 0 {
+ panic("lo.ChunkString: Size parameter must be greater than 0")
+ }
+
+ if len(str) == 0 {
+ return []T{""}
+ }
+
+ if size >= len(str) {
+ return []T{str}
+ }
+
+ var chunks = make([]T, 0, ((len(str)-1)/size)+1)
+ currentLen := 0
+ currentStart := 0
+ for i := range str {
+ if currentLen == size {
+ chunks = append(chunks, str[currentStart:i])
+ currentLen = 0
+ currentStart = i
+ }
+ currentLen++
+ }
+ chunks = append(chunks, str[currentStart:])
+ return chunks
+}
+
+// RuneLength is an alias to utf8.RuneCountInString which returns the number of runes in string.
+// Play: https://go.dev/play/p/tuhgW_lWY8l
+func RuneLength(str string) int {
+ return utf8.RuneCountInString(str)
+}
+
+// PascalCase converts string to pascal case.
+func PascalCase(str string) string {
+ items := Words(str)
+ for i := range items {
+ items[i] = Capitalize(items[i])
+ }
+ return strings.Join(items, "")
+}
+
+// CamelCase converts string to camel case.
+func CamelCase(str string) string {
+ items := Words(str)
+ for i, item := range items {
+ item = strings.ToLower(item)
+ if i > 0 {
+ item = Capitalize(item)
+ }
+ items[i] = item
+ }
+ return strings.Join(items, "")
+}
+
+// KebabCase converts string to kebab case.
+func KebabCase(str string) string {
+ items := Words(str)
+ for i := range items {
+ items[i] = strings.ToLower(items[i])
+ }
+ return strings.Join(items, "-")
+}
+
+// SnakeCase converts string to snake case.
+func SnakeCase(str string) string {
+ items := Words(str)
+ for i := range items {
+ items[i] = strings.ToLower(items[i])
+ }
+ return strings.Join(items, "_")
+}
+
+// Words splits string into an array of its words.
+func Words(str string) []string {
+ str = splitWordReg.ReplaceAllString(str, `$1$3$5$7 $2$4$6$8$9`)
+ // example: Int8Value => Int 8Value => Int 8 Value
+ str = splitNumberLetterReg.ReplaceAllString(str, "$1 $2")
+ var result strings.Builder
+ for _, r := range str {
+ if unicode.IsLetter(r) || unicode.IsDigit(r) {
+ result.WriteRune(r)
+ } else {
+ result.WriteRune(' ')
+ }
+ }
+ return strings.Fields(result.String())
+}
+
+// Capitalize converts the first character of string to upper case and the remaining to lower case.
+func Capitalize(str string) string {
+ return cases.Title(language.English).String(str)
+}
+
+// Ellipsis trims and truncates a string to a specified length **in bytes** and appends an ellipsis
+// if truncated. If the string contains non-ASCII characters (which may occupy multiple bytes in UTF-8),
+// truncating by byte length may split a character in the middle, potentially resulting in garbled output.
+func Ellipsis(str string, length int) string {
+ str = strings.TrimSpace(str)
+
+ if len(str) > length {
+ if len(str) < 3 || length < 3 {
+ return "..."
+ }
+ return strings.TrimSpace(str[0:length-3]) + "..."
+ }
+
+ return str
+}
+
+// Elipse trims and truncates a string to a specified length and appends an ellipsis if truncated.
+//
+// Deprecated: Use Ellipsis instead.
+func Elipse(str string, length int) string {
+ return Ellipsis(str, length)
+}
diff --git a/vendor/github.com/samber/lo/time.go b/vendor/github.com/samber/lo/time.go
new file mode 100644
index 00000000..e98e80f9
--- /dev/null
+++ b/vendor/github.com/samber/lo/time.go
@@ -0,0 +1,85 @@
+package lo
+
+import "time"
+
+// Duration returns the time taken to execute a function.
+func Duration(cb func()) time.Duration {
+ return Duration0(cb)
+}
+
+// Duration0 returns the time taken to execute a function.
+func Duration0(cb func()) time.Duration {
+ start := time.Now()
+ cb()
+ return time.Since(start)
+}
+
+// Duration1 returns the time taken to execute a function.
+func Duration1[A any](cb func() A) (A, time.Duration) {
+ start := time.Now()
+ a := cb()
+ return a, time.Since(start)
+}
+
+// Duration2 returns the time taken to execute a function.
+func Duration2[A, B any](cb func() (A, B)) (A, B, time.Duration) {
+ start := time.Now()
+ a, b := cb()
+ return a, b, time.Since(start)
+}
+
+// Duration3 returns the time taken to execute a function.
+func Duration3[A, B, C any](cb func() (A, B, C)) (A, B, C, time.Duration) {
+ start := time.Now()
+ a, b, c := cb()
+ return a, b, c, time.Since(start)
+}
+
+// Duration4 returns the time taken to execute a function.
+func Duration4[A, B, C, D any](cb func() (A, B, C, D)) (A, B, C, D, time.Duration) {
+ start := time.Now()
+ a, b, c, d := cb()
+ return a, b, c, d, time.Since(start)
+}
+
+// Duration5 returns the time taken to execute a function.
+func Duration5[A, B, C, D, E any](cb func() (A, B, C, D, E)) (A, B, C, D, E, time.Duration) {
+ start := time.Now()
+ a, b, c, d, e := cb()
+ return a, b, c, d, e, time.Since(start)
+}
+
+// Duration6 returns the time taken to execute a function.
+func Duration6[A, B, C, D, E, F any](cb func() (A, B, C, D, E, F)) (A, B, C, D, E, F, time.Duration) {
+ start := time.Now()
+ a, b, c, d, e, f := cb()
+ return a, b, c, d, e, f, time.Since(start)
+}
+
+// Duration7 returns the time taken to execute a function.
+func Duration7[A, B, C, D, E, F, G any](cb func() (A, B, C, D, E, F, G)) (A, B, C, D, E, F, G, time.Duration) {
+ start := time.Now()
+ a, b, c, d, e, f, g := cb()
+ return a, b, c, d, e, f, g, time.Since(start)
+}
+
+// Duration8 returns the time taken to execute a function.
+func Duration8[A, B, C, D, E, F, G, H any](cb func() (A, B, C, D, E, F, G, H)) (A, B, C, D, E, F, G, H, time.Duration) {
+ start := time.Now()
+ a, b, c, d, e, f, g, h := cb()
+ return a, b, c, d, e, f, g, h, time.Since(start)
+}
+
+// Duration9 returns the time taken to execute a function.
+func Duration9[A, B, C, D, E, F, G, H, I any](cb func() (A, B, C, D, E, F, G, H, I)) (A, B, C, D, E, F, G, H, I, time.Duration) {
+ start := time.Now()
+ a, b, c, d, e, f, g, h, i := cb()
+ return a, b, c, d, e, f, g, h, i, time.Since(start)
+}
+
+// Duration10 returns the time taken to execute a function.
+func Duration10[A, B, C, D, E, F, G, H, I, J any](cb func() (A, B, C, D, E, F, G, H, I, J)) (A, B, C, D, E, F, G, H, I, J, time.Duration) {
+ start := time.Now()
+ a, b, c, d, e, f, g, h, i, j := cb()
+ return a, b, c, d, e, f, g, h, i, j, time.Since(start)
+}
diff --git a/vendor/github.com/samber/lo/tuples.go b/vendor/github.com/samber/lo/tuples.go
new file mode 100644
index 00000000..e355d0ca
--- /dev/null
+++ b/vendor/github.com/samber/lo/tuples.go
@@ -0,0 +1,1149 @@
+package lo
+
+// T2 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T2[A, B any](a A, b B) Tuple2[A, B] {
+ return Tuple2[A, B]{A: a, B: b}
+}
+
+// T3 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T3[A, B, C any](a A, b B, c C) Tuple3[A, B, C] {
+ return Tuple3[A, B, C]{A: a, B: b, C: c}
+}
+
+// T4 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T4[A, B, C, D any](a A, b B, c C, d D) Tuple4[A, B, C, D] {
+ return Tuple4[A, B, C, D]{A: a, B: b, C: c, D: d}
+}
+
+// T5 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T5[A, B, C, D, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E] {
+ return Tuple5[A, B, C, D, E]{A: a, B: b, C: c, D: d, E: e}
+}
+
+// T6 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T6[A, B, C, D, E, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F] {
+ return Tuple6[A, B, C, D, E, F]{A: a, B: b, C: c, D: d, E: e, F: f}
+}
+
+// T7 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T7[A, B, C, D, E, F, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G] {
+ return Tuple7[A, B, C, D, E, F, G]{A: a, B: b, C: c, D: d, E: e, F: f, G: g}
+}
+
+// T8 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T8[A, B, C, D, E, F, G, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H] {
+ return Tuple8[A, B, C, D, E, F, G, H]{A: a, B: b, C: c, D: d, E: e, F: f, G: g, H: h}
+}
+
+// T9 creates a tuple from a list of values.
+// Play: https://go.dev/play/p/IllL3ZO4BQm
+func T9[A, B, C, D, E, F, G, H, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) Tuple9[A, B, C, D, E, F, G, H, I] {
+ return Tuple9[A, B, C, D, E, F, G, H, I]{A: a, B: b, C: c, D: d, E: e, F: f, G: g, H: h, I: i}
+}
+
+// Unpack2 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack2[A, B any](tuple Tuple2[A, B]) (A, B) {
+ return tuple.A, tuple.B
+}
+
+// Unpack3 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack3[A, B, C any](tuple Tuple3[A, B, C]) (A, B, C) {
+ return tuple.A, tuple.B, tuple.C
+}
+
+// Unpack4 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack4[A, B, C, D any](tuple Tuple4[A, B, C, D]) (A, B, C, D) {
+ return tuple.A, tuple.B, tuple.C, tuple.D
+}
+
+// Unpack5 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack5[A, B, C, D, E any](tuple Tuple5[A, B, C, D, E]) (A, B, C, D, E) {
+ return tuple.A, tuple.B, tuple.C, tuple.D, tuple.E
+}
+
+// Unpack6 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack6[A, B, C, D, E, F any](tuple Tuple6[A, B, C, D, E, F]) (A, B, C, D, E, F) {
+ return tuple.A, tuple.B, tuple.C, tuple.D, tuple.E, tuple.F
+}
+
+// Unpack7 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack7[A, B, C, D, E, F, G any](tuple Tuple7[A, B, C, D, E, F, G]) (A, B, C, D, E, F, G) {
+ return tuple.A, tuple.B, tuple.C, tuple.D, tuple.E, tuple.F, tuple.G
+}
+
+// Unpack8 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack8[A, B, C, D, E, F, G, H any](tuple Tuple8[A, B, C, D, E, F, G, H]) (A, B, C, D, E, F, G, H) {
+ return tuple.A, tuple.B, tuple.C, tuple.D, tuple.E, tuple.F, tuple.G, tuple.H
+}
+
+// Unpack9 returns values contained in tuple.
+// Play: https://go.dev/play/p/xVP_k0kJ96W
+func Unpack9[A, B, C, D, E, F, G, H, I any](tuple Tuple9[A, B, C, D, E, F, G, H, I]) (A, B, C, D, E, F, G, H, I) {
+ return tuple.A, tuple.B, tuple.C, tuple.D, tuple.E, tuple.F, tuple.G, tuple.H, tuple.I
+}
+
+// Zip2 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip2[A, B any](a []A, b []B) []Tuple2[A, B] {
+ size := Max([]int{len(a), len(b)})
+
+ result := make([]Tuple2[A, B], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+
+ result = append(result, Tuple2[A, B]{
+ A: _a,
+ B: _b,
+ })
+ }
+
+ return result
+}
+
+// Zip3 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip3[A, B, C any](a []A, b []B, c []C) []Tuple3[A, B, C] {
+ size := Max([]int{len(a), len(b), len(c)})
+
+ result := make([]Tuple3[A, B, C], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+
+ result = append(result, Tuple3[A, B, C]{
+ A: _a,
+ B: _b,
+ C: _c,
+ })
+ }
+
+ return result
+}
+
+// Zip4 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip4[A, B, C, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D] {
+ size := Max([]int{len(a), len(b), len(c), len(d)})
+
+ result := make([]Tuple4[A, B, C, D], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+
+ result = append(result, Tuple4[A, B, C, D]{
+ A: _a,
+ B: _b,
+ C: _c,
+ D: _d,
+ })
+ }
+
+ return result
+}
+
+// Zip5 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip5[A, B, C, D, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E] {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e)})
+
+ result := make([]Tuple5[A, B, C, D, E], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+
+ result = append(result, Tuple5[A, B, C, D, E]{
+ A: _a,
+ B: _b,
+ C: _c,
+ D: _d,
+ E: _e,
+ })
+ }
+
+ return result
+}
+
+// Zip6 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip6[A, B, C, D, E, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F] {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f)})
+
+ result := make([]Tuple6[A, B, C, D, E, F], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+
+ result = append(result, Tuple6[A, B, C, D, E, F]{
+ A: _a,
+ B: _b,
+ C: _c,
+ D: _d,
+ E: _e,
+ F: _f,
+ })
+ }
+
+ return result
+}
+
+// Zip7 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip7[A, B, C, D, E, F, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G] {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g)})
+
+ result := make([]Tuple7[A, B, C, D, E, F, G], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+ _g, _ := Nth(g, index)
+
+ result = append(result, Tuple7[A, B, C, D, E, F, G]{
+ A: _a,
+ B: _b,
+ C: _c,
+ D: _d,
+ E: _e,
+ F: _f,
+ G: _g,
+ })
+ }
+
+ return result
+}
+
+// Zip8 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip8[A, B, C, D, E, F, G, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H] {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h)})
+
+ result := make([]Tuple8[A, B, C, D, E, F, G, H], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+ _g, _ := Nth(g, index)
+ _h, _ := Nth(h, index)
+
+ result = append(result, Tuple8[A, B, C, D, E, F, G, H]{
+ A: _a,
+ B: _b,
+ C: _c,
+ D: _d,
+ E: _e,
+ F: _f,
+ G: _g,
+ H: _h,
+ })
+ }
+
+ return result
+}
+
+// Zip9 creates a slice of grouped elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+// Play: https://go.dev/play/p/jujaA6GaJTp
+func Zip9[A, B, C, D, E, F, G, H, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I] {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i)})
+
+ result := make([]Tuple9[A, B, C, D, E, F, G, H, I], 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+ _g, _ := Nth(g, index)
+ _h, _ := Nth(h, index)
+ _i, _ := Nth(i, index)
+
+ result = append(result, Tuple9[A, B, C, D, E, F, G, H, I]{
+ A: _a,
+ B: _b,
+ C: _c,
+ D: _d,
+ E: _e,
+ F: _f,
+ G: _g,
+ H: _h,
+ I: _i,
+ })
+ }
+
+ return result
+}
+
+// ZipBy2 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy2[A any, B any, Out any](a []A, b []B, iteratee func(a A, b B) Out) []Out {
+ size := Max([]int{len(a), len(b)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+
+ result = append(result, iteratee(_a, _b))
+ }
+
+ return result
+}
+
+// ZipBy3 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy3[A any, B any, C any, Out any](a []A, b []B, c []C, iteratee func(a A, b B, c C) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+
+ result = append(result, iteratee(_a, _b, _c))
+ }
+
+ return result
+}
+
+// ZipBy4 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy4[A any, B any, C any, D any, Out any](a []A, b []B, c []C, d []D, iteratee func(a A, b B, c C, d D) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c), len(d)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+
+ result = append(result, iteratee(_a, _b, _c, _d))
+ }
+
+ return result
+}
+
+// ZipBy5 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy5[A any, B any, C any, D any, E any, Out any](a []A, b []B, c []C, d []D, e []E, iteratee func(a A, b B, c C, d D, e E) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+
+ result = append(result, iteratee(_a, _b, _c, _d, _e))
+ }
+
+ return result
+}
+
+// ZipBy6 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy6[A any, B any, C any, D any, E any, F any, Out any](a []A, b []B, c []C, d []D, e []E, f []F, iteratee func(a A, b B, c C, d D, e E, f F) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+
+ result = append(result, iteratee(_a, _b, _c, _d, _e, _f))
+ }
+
+ return result
+}
+
+// ZipBy7 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy7[A any, B any, C any, D any, E any, F any, G any, Out any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, iteratee func(a A, b B, c C, d D, e E, f F, g G) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+ _g, _ := Nth(g, index)
+
+ result = append(result, iteratee(_a, _b, _c, _d, _e, _f, _g))
+ }
+
+ return result
+}
+
+// ZipBy8 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy8[A any, B any, C any, D any, E any, F any, G any, H any, Out any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, iteratee func(a A, b B, c C, d D, e E, f F, g G, h H) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+ _g, _ := Nth(g, index)
+ _h, _ := Nth(h, index)
+
+ result = append(result, iteratee(_a, _b, _c, _d, _e, _f, _g, _h))
+ }
+
+ return result
+}
+
+// ZipBy9 creates a slice of transformed elements, the first of which contains the first elements
+// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
+// When collections have different size, the Tuple attributes are filled with zero value.
+func ZipBy9[A any, B any, C any, D any, E any, F any, G any, H any, I any, Out any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, iteratee func(a A, b B, c C, d D, e E, f F, g G, h H, i I) Out) []Out {
+ size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i)})
+
+ result := make([]Out, 0, size)
+
+ for index := 0; index < size; index++ {
+ _a, _ := Nth(a, index)
+ _b, _ := Nth(b, index)
+ _c, _ := Nth(c, index)
+ _d, _ := Nth(d, index)
+ _e, _ := Nth(e, index)
+ _f, _ := Nth(f, index)
+ _g, _ := Nth(g, index)
+ _h, _ := Nth(h, index)
+ _i, _ := Nth(i, index)
+
+ result = append(result, iteratee(_a, _b, _c, _d, _e, _f, _g, _h, _i))
+ }
+
+ return result
+}
+
+// Unzip2 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip2[A, B any](tuples []Tuple2[A, B]) ([]A, []B) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ }
+
+ return r1, r2
+}
+
+// Unzip3 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip3[A, B, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ }
+
+ return r1, r2, r3
+}
+
+// Unzip4 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip4[A, B, C, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ r4 = append(r4, tuples[i].D)
+ }
+
+ return r1, r2, r3, r4
+}
+
+// Unzip5 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip5[A, B, C, D, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ r4 = append(r4, tuples[i].D)
+ r5 = append(r5, tuples[i].E)
+ }
+
+ return r1, r2, r3, r4, r5
+}
+
+// Unzip6 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip6[A, B, C, D, E, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ r4 = append(r4, tuples[i].D)
+ r5 = append(r5, tuples[i].E)
+ r6 = append(r6, tuples[i].F)
+ }
+
+ return r1, r2, r3, r4, r5, r6
+}
+
+// Unzip7 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip7[A, B, C, D, E, F, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+ r7 := make([]G, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ r4 = append(r4, tuples[i].D)
+ r5 = append(r5, tuples[i].E)
+ r6 = append(r6, tuples[i].F)
+ r7 = append(r7, tuples[i].G)
+ }
+
+ return r1, r2, r3, r4, r5, r6, r7
+}
+
+// Unzip8 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip8[A, B, C, D, E, F, G, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+ r7 := make([]G, 0, size)
+ r8 := make([]H, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ r4 = append(r4, tuples[i].D)
+ r5 = append(r5, tuples[i].E)
+ r6 = append(r6, tuples[i].F)
+ r7 = append(r7, tuples[i].G)
+ r8 = append(r8, tuples[i].H)
+ }
+
+ return r1, r2, r3, r4, r5, r6, r7, r8
+}
+
+// Unzip9 accepts an array of grouped elements and creates an array regrouping the elements
+// to their pre-zip configuration.
+// Play: https://go.dev/play/p/ciHugugvaAW
+func Unzip9[A, B, C, D, E, F, G, H, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I) {
+ size := len(tuples)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+ r7 := make([]G, 0, size)
+ r8 := make([]H, 0, size)
+ r9 := make([]I, 0, size)
+
+ for i := range tuples {
+ r1 = append(r1, tuples[i].A)
+ r2 = append(r2, tuples[i].B)
+ r3 = append(r3, tuples[i].C)
+ r4 = append(r4, tuples[i].D)
+ r5 = append(r5, tuples[i].E)
+ r6 = append(r6, tuples[i].F)
+ r7 = append(r7, tuples[i].G)
+ r8 = append(r8, tuples[i].H)
+ r9 = append(r9, tuples[i].I)
+ }
+
+ return r1, r2, r3, r4, r5, r6, r7, r8, r9
+}
+
+// UnzipBy2 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy2[In any, A any, B any](items []In, iteratee func(In) (a A, b B)) ([]A, []B) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+
+ for i := range items {
+ a, b := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ }
+
+ return r1, r2
+}
+
+// UnzipBy3 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy3[In any, A any, B any, C any](items []In, iteratee func(In) (a A, b B, c C)) ([]A, []B, []C) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+
+ for i := range items {
+ a, b, c := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ }
+
+ return r1, r2, r3
+}
+
+// UnzipBy4 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy4[In any, A any, B any, C any, D any](items []In, iteratee func(In) (a A, b B, c C, d D)) ([]A, []B, []C, []D) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+
+ for i := range items {
+ a, b, c, d := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ r4 = append(r4, d)
+ }
+
+ return r1, r2, r3, r4
+}
+
+// UnzipBy5 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy5[In any, A any, B any, C any, D any, E any](items []In, iteratee func(In) (a A, b B, c C, d D, e E)) ([]A, []B, []C, []D, []E) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+
+ for i := range items {
+ a, b, c, d, e := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ r4 = append(r4, d)
+ r5 = append(r5, e)
+ }
+
+ return r1, r2, r3, r4, r5
+}
+
+// UnzipBy6 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy6[In any, A any, B any, C any, D any, E any, F any](items []In, iteratee func(In) (a A, b B, c C, d D, e E, f F)) ([]A, []B, []C, []D, []E, []F) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+
+ for i := range items {
+ a, b, c, d, e, f := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ r4 = append(r4, d)
+ r5 = append(r5, e)
+ r6 = append(r6, f)
+ }
+
+ return r1, r2, r3, r4, r5, r6
+}
+
+// UnzipBy7 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy7[In any, A any, B any, C any, D any, E any, F any, G any](items []In, iteratee func(In) (a A, b B, c C, d D, e E, f F, g G)) ([]A, []B, []C, []D, []E, []F, []G) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+ r7 := make([]G, 0, size)
+
+ for i := range items {
+ a, b, c, d, e, f, g := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ r4 = append(r4, d)
+ r5 = append(r5, e)
+ r6 = append(r6, f)
+ r7 = append(r7, g)
+ }
+
+ return r1, r2, r3, r4, r5, r6, r7
+}
+
+// UnzipBy8 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy8[In any, A any, B any, C any, D any, E any, F any, G any, H any](items []In, iteratee func(In) (a A, b B, c C, d D, e E, f F, g G, h H)) ([]A, []B, []C, []D, []E, []F, []G, []H) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+ r7 := make([]G, 0, size)
+ r8 := make([]H, 0, size)
+
+ for i := range items {
+ a, b, c, d, e, f, g, h := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ r4 = append(r4, d)
+ r5 = append(r5, e)
+ r6 = append(r6, f)
+ r7 = append(r7, g)
+ r8 = append(r8, h)
+ }
+
+ return r1, r2, r3, r4, r5, r6, r7, r8
+}
+
+// UnzipBy9 iterates over a collection and creates an array regrouping the elements
+// to their pre-zip configuration.
+func UnzipBy9[In any, A any, B any, C any, D any, E any, F any, G any, H any, I any](items []In, iteratee func(In) (a A, b B, c C, d D, e E, f F, g G, h H, i I)) ([]A, []B, []C, []D, []E, []F, []G, []H, []I) {
+ size := len(items)
+ r1 := make([]A, 0, size)
+ r2 := make([]B, 0, size)
+ r3 := make([]C, 0, size)
+ r4 := make([]D, 0, size)
+ r5 := make([]E, 0, size)
+ r6 := make([]F, 0, size)
+ r7 := make([]G, 0, size)
+ r8 := make([]H, 0, size)
+ r9 := make([]I, 0, size)
+
+ for i := range items {
+ a, b, c, d, e, f, g, h, i := iteratee(items[i])
+ r1 = append(r1, a)
+ r2 = append(r2, b)
+ r3 = append(r3, c)
+ r4 = append(r4, d)
+ r5 = append(r5, e)
+ r6 = append(r6, f)
+ r7 = append(r7, g)
+ r8 = append(r8, h)
+ r9 = append(r9, i)
+ }
+
+ return r1, r2, r3, r4, r5, r6, r7, r8, r9
+}
+
+// CrossJoin2 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin2[A, B any](listA []A, listB []B) []Tuple2[A, B] {
+ return CrossJoinBy2(listA, listB, T2[A, B])
+}
+
+// CrossJoin3 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin3[A, B, C any](listA []A, listB []B, listC []C) []Tuple3[A, B, C] {
+ return CrossJoinBy3(listA, listB, listC, T3[A, B, C])
+}
+
+// CrossJoin4 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin4[A, B, C, D any](listA []A, listB []B, listC []C, listD []D) []Tuple4[A, B, C, D] {
+ return CrossJoinBy4(listA, listB, listC, listD, T4[A, B, C, D])
+}
+
+// CrossJoin5 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin5[A, B, C, D, E any](listA []A, listB []B, listC []C, listD []D, listE []E) []Tuple5[A, B, C, D, E] {
+ return CrossJoinBy5(listA, listB, listC, listD, listE, T5[A, B, C, D, E])
+}
+
+// CrossJoin6 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin6[A, B, C, D, E, F any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F) []Tuple6[A, B, C, D, E, F] {
+ return CrossJoinBy6(listA, listB, listC, listD, listE, listF, T6[A, B, C, D, E, F])
+}
+
+// CrossJoin7 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin7[A, B, C, D, E, F, G any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, listG []G) []Tuple7[A, B, C, D, E, F, G] {
+ return CrossJoinBy7(listA, listB, listC, listD, listE, listF, listG, T7[A, B, C, D, E, F, G])
+}
+
+// CrossJoin8 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin8[A, B, C, D, E, F, G, H any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, listG []G, listH []H) []Tuple8[A, B, C, D, E, F, G, H] {
+ return CrossJoinBy8(listA, listB, listC, listD, listE, listF, listG, listH, T8[A, B, C, D, E, F, G, H])
+}
+
+// CrossJoin9 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments.
+// It returns an empty list if a list is empty.
+func CrossJoin9[A, B, C, D, E, F, G, H, I any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, listG []G, listH []H, listI []I) []Tuple9[A, B, C, D, E, F, G, H, I] {
+ return CrossJoinBy9(listA, listB, listC, listD, listE, listF, listG, listH, listI, T9[A, B, C, D, E, F, G, H, I])
+}
+
+// CrossJoinBy2 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy2[A, B, Out any](listA []A, listB []B, project func(a A, b B) Out) []Out {
+ size := len(listA) * len(listB)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ result = append(result, project(a, b))
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy3 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy3[A, B, C, Out any](listA []A, listB []B, listC []C, project func(a A, b B, c C) Out) []Out {
+ size := len(listA) * len(listB) * len(listC)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ result = append(result, project(a, b, c))
+ }
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy4 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy4[A, B, C, D, Out any](listA []A, listB []B, listC []C, listD []D, project func(a A, b B, c C, d D) Out) []Out {
+ size := len(listA) * len(listB) * len(listC) * len(listD)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ for _, d := range listD {
+ result = append(result, project(a, b, c, d))
+ }
+ }
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy5 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy5[A, B, C, D, E, Out any](listA []A, listB []B, listC []C, listD []D, listE []E, project func(a A, b B, c C, d D, e E) Out) []Out {
+ size := len(listA) * len(listB) * len(listC) * len(listD) * len(listE)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ for _, d := range listD {
+ for _, e := range listE {
+ result = append(result, project(a, b, c, d, e))
+ }
+ }
+ }
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy6 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy6[A, B, C, D, E, F, Out any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, project func(a A, b B, c C, d D, e E, f F) Out) []Out {
+ size := len(listA) * len(listB) * len(listC) * len(listD) * len(listE) * len(listF)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ for _, d := range listD {
+ for _, e := range listE {
+ for _, f := range listF {
+ result = append(result, project(a, b, c, d, e, f))
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy7 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy7[A, B, C, D, E, F, G, Out any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, listG []G, project func(a A, b B, c C, d D, e E, f F, g G) Out) []Out {
+ size := len(listA) * len(listB) * len(listC) * len(listD) * len(listE) * len(listF) * len(listG)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ for _, d := range listD {
+ for _, e := range listE {
+ for _, f := range listF {
+ for _, g := range listG {
+ result = append(result, project(a, b, c, d, e, f, g))
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy8 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy8[A, B, C, D, E, F, G, H, Out any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, listG []G, listH []H, project func(a A, b B, c C, d D, e E, f F, g G, h H) Out) []Out {
+ size := len(listA) * len(listB) * len(listC) * len(listD) * len(listE) * len(listF) * len(listG) * len(listH)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ for _, d := range listD {
+ for _, e := range listE {
+ for _, f := range listF {
+ for _, g := range listG {
+ for _, h := range listH {
+ result = append(result, project(a, b, c, d, e, f, g, h))
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result
+}
+
+// CrossJoinBy9 combines every items from one list with every items from others.
+// It is the cartesian product of lists received as arguments. The project function
+// is used to create the output values.
+// It returns an empty list if a list is empty.
+func CrossJoinBy9[A, B, C, D, E, F, G, H, I, Out any](listA []A, listB []B, listC []C, listD []D, listE []E, listF []F, listG []G, listH []H, listI []I, project func(a A, b B, c C, d D, e E, f F, g G, h H, i I) Out) []Out {
+ size := len(listA) * len(listB) * len(listC) * len(listD) * len(listE) * len(listF) * len(listG) * len(listH) * len(listI)
+ if size == 0 {
+ return []Out{}
+ }
+
+ result := make([]Out, 0, size)
+
+ for _, a := range listA {
+ for _, b := range listB {
+ for _, c := range listC {
+ for _, d := range listD {
+ for _, e := range listE {
+ for _, f := range listF {
+ for _, g := range listG {
+ for _, h := range listH {
+ for _, i := range listI {
+ result = append(result, project(a, b, c, d, e, f, g, h, i))
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result
+}
diff --git a/vendor/github.com/samber/lo/type_manipulation.go b/vendor/github.com/samber/lo/type_manipulation.go
new file mode 100644
index 00000000..bcf990cd
--- /dev/null
+++ b/vendor/github.com/samber/lo/type_manipulation.go
@@ -0,0 +1,189 @@
+package lo
+
+import "reflect"
+
+// IsNil checks if a value is nil or if it's a reference type with a nil underlying value.
+func IsNil(x any) bool {
+ defer func() { recover() }() // nolint:errcheck
+ return x == nil || reflect.ValueOf(x).IsNil()
+}
+
+// IsNotNil checks if a value is not nil or if it's not a reference type with a nil underlying value.
+func IsNotNil(x any) bool {
+ return !IsNil(x)
+}
+
+// ToPtr returns a pointer copy of value.
+func ToPtr[T any](x T) *T {
+ return &x
+}
+
+// Nil returns a nil pointer of type.
+func Nil[T any]() *T {
+ return nil
+}
+
+// EmptyableToPtr returns a pointer copy of value if it's nonzero.
+// Otherwise, returns nil pointer.
+func EmptyableToPtr[T any](x T) *T {
+ // 🤮
+ isZero := reflect.ValueOf(&x).Elem().IsZero()
+ if isZero {
+ return nil
+ }
+
+ return &x
+}
+
+// FromPtr returns the pointer value or empty.
+func FromPtr[T any](x *T) T {
+ if x == nil {
+ return Empty[T]()
+ }
+
+ return *x
+}
+
+// FromPtrOr returns the pointer value or the fallback value.
+func FromPtrOr[T any](x *T, fallback T) T {
+ if x == nil {
+ return fallback
+ }
+
+ return *x
+}
+
+// ToSlicePtr returns a slice of pointer copy of value.
+func ToSlicePtr[T any](collection []T) []*T {
+ result := make([]*T, len(collection))
+
+ for i := range collection {
+ result[i] = &collection[i]
+ }
+ return result
+}
+
+// FromSlicePtr returns a slice with the pointer values.
+// Returns a zero value in case of a nil pointer element.
+func FromSlicePtr[T any](collection []*T) []T {
+ return Map(collection, func(x *T, _ int) T {
+ if x == nil {
+ return Empty[T]()
+ }
+ return *x
+ })
+}
+
+// FromSlicePtrOr returns a slice with the pointer values or the fallback value.
+// Play: https://go.dev/play/p/lbunFvzlUDX
+func FromSlicePtrOr[T any](collection []*T, fallback T) []T {
+ return Map(collection, func(x *T, _ int) T {
+ if x == nil {
+ return fallback
+ }
+ return *x
+ })
+}
+
+// ToAnySlice returns a slice with all elements mapped to `any` type
+func ToAnySlice[T any](collection []T) []any {
+ result := make([]any, len(collection))
+ for i := range collection {
+ result[i] = collection[i]
+ }
+ return result
+}
+
+// FromAnySlice returns an `any` slice with all elements mapped to a type.
+// Returns false in case of type conversion failure.
+func FromAnySlice[T any](in []any) (out []T, ok bool) {
+ defer func() {
+ if r := recover(); r != nil {
+ out = []T{}
+ ok = false
+ }
+ }()
+
+ result := make([]T, len(in))
+ for i := range in {
+ result[i] = in[i].(T)
+ }
+ return result, true
+}
+
+// Empty returns the zero value (https://go.dev/ref/spec#The_zero_value).
+func Empty[T any]() T {
+ var zero T
+ return zero
+}
+
+// IsEmpty returns true if argument is a zero value.
+func IsEmpty[T comparable](v T) bool {
+ var zero T
+ return zero == v
+}
+
+// IsNotEmpty returns true if argument is not a zero value.
+func IsNotEmpty[T comparable](v T) bool {
+ var zero T
+ return zero != v
+}
+
+// Coalesce returns the first non-empty arguments. Arguments must be comparable.
+func Coalesce[T comparable](values ...T) (result T, ok bool) {
+ for i := range values {
+ if values[i] != result {
+ result = values[i]
+ ok = true
+ return
+ }
+ }
+
+ return
+}
+
+// CoalesceOrEmpty returns the first non-empty arguments. Arguments must be comparable.
+func CoalesceOrEmpty[T comparable](v ...T) T {
+ result, _ := Coalesce(v...)
+ return result
+}
+
+// CoalesceSlice returns the first non-zero slice.
+func CoalesceSlice[T any](v ...[]T) ([]T, bool) {
+ for i := range v {
+ if v[i] != nil && len(v[i]) > 0 {
+ return v[i], true
+ }
+ }
+ return []T{}, false
+}
+
+// CoalesceSliceOrEmpty returns the first non-zero slice.
+func CoalesceSliceOrEmpty[T any](v ...[]T) []T {
+ for i := range v {
+ if v[i] != nil && len(v[i]) > 0 {
+ return v[i]
+ }
+ }
+ return []T{}
+}
+
+// CoalesceMap returns the first non-zero map.
+func CoalesceMap[K comparable, V any](v ...map[K]V) (map[K]V, bool) {
+ for i := range v {
+ if v[i] != nil && len(v[i]) > 0 {
+ return v[i], true
+ }
+ }
+ return map[K]V{}, false
+}
+
+// CoalesceMapOrEmpty returns the first non-zero map.
+func CoalesceMapOrEmpty[K comparable, V any](v ...map[K]V) map[K]V {
+ for i := range v {
+ if v[i] != nil && len(v[i]) > 0 {
+ return v[i]
+ }
+ }
+ return map[K]V{}
+}
diff --git a/vendor/github.com/samber/lo/types.go b/vendor/github.com/samber/lo/types.go
new file mode 100644
index 00000000..1c6f0d00
--- /dev/null
+++ b/vendor/github.com/samber/lo/types.go
@@ -0,0 +1,123 @@
+package lo
+
+// Entry defines a key/value pairs.
+type Entry[K comparable, V any] struct {
+ Key K
+ Value V
+}
+
+// Tuple2 is a group of 2 elements (pair).
+type Tuple2[A, B any] struct {
+ A A
+ B B
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple2[A, B]) Unpack() (A, B) {
+ return t.A, t.B
+}
+
+// Tuple3 is a group of 3 elements.
+type Tuple3[A, B, C any] struct {
+ A A
+ B B
+ C C
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple3[A, B, C]) Unpack() (A, B, C) {
+ return t.A, t.B, t.C
+}
+
+// Tuple4 is a group of 4 elements.
+type Tuple4[A, B, C, D any] struct {
+ A A
+ B B
+ C C
+ D D
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple4[A, B, C, D]) Unpack() (A, B, C, D) {
+ return t.A, t.B, t.C, t.D
+}
+
+// Tuple5 is a group of 5 elements.
+type Tuple5[A, B, C, D, E any] struct {
+ A A
+ B B
+ C C
+ D D
+ E E
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple5[A, B, C, D, E]) Unpack() (A, B, C, D, E) {
+ return t.A, t.B, t.C, t.D, t.E
+}
+
+// Tuple6 is a group of 6 elements.
+type Tuple6[A, B, C, D, E, F any] struct {
+ A A
+ B B
+ C C
+ D D
+ E E
+ F F
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple6[A, B, C, D, E, F]) Unpack() (A, B, C, D, E, F) {
+ return t.A, t.B, t.C, t.D, t.E, t.F
+}
+
+// Tuple7 is a group of 7 elements.
+type Tuple7[A, B, C, D, E, F, G any] struct {
+ A A
+ B B
+ C C
+ D D
+ E E
+ F F
+ G G
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple7[A, B, C, D, E, F, G]) Unpack() (A, B, C, D, E, F, G) {
+ return t.A, t.B, t.C, t.D, t.E, t.F, t.G
+}
+
+// Tuple8 is a group of 8 elements.
+type Tuple8[A, B, C, D, E, F, G, H any] struct {
+ A A
+ B B
+ C C
+ D D
+ E E
+ F F
+ G G
+ H H
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple8[A, B, C, D, E, F, G, H]) Unpack() (A, B, C, D, E, F, G, H) {
+ return t.A, t.B, t.C, t.D, t.E, t.F, t.G, t.H
+}
+
+// Tuple9 is a group of 9 elements.
+type Tuple9[A, B, C, D, E, F, G, H, I any] struct {
+ A A
+ B B
+ C C
+ D D
+ E E
+ F F
+ G G
+ H H
+ I I
+}
+
+// Unpack returns values contained in tuple.
+func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unpack() (A, B, C, D, E, F, G, H, I) {
+ return t.A, t.B, t.C, t.D, t.E, t.F, t.G, t.H, t.I
+}