mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
use boxlayout from lazycore
This commit is contained in:
134
vendor/github.com/samber/lo/map.go
generated
vendored
134
vendor/github.com/samber/lo/map.go
generated
vendored
@ -1,10 +1,11 @@
|
||||
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 {
|
||||
result := make([]K, 0, len(in))
|
||||
|
||||
for k, _ := range in {
|
||||
for k := range in {
|
||||
result = append(result, k)
|
||||
}
|
||||
|
||||
@ -12,6 +13,7 @@ func Keys[K comparable, V any](in map[K]V) []K {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
result := make([]V, 0, len(in))
|
||||
|
||||
@ -22,7 +24,80 @@ func Values[K comparable, V any](in map[K]V) []V {
|
||||
return result
|
||||
}
|
||||
|
||||
// PickBy returns same map type filtered by given predicate.
|
||||
// Play: https://go.dev/play/p/kdg8GR_QMmf
|
||||
func PickBy[K comparable, V any](in map[K]V, predicate func(K, V) bool) map[K]V {
|
||||
r := map[K]V{}
|
||||
for k, v := range in {
|
||||
if predicate(k, v) {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// PickByKeys returns same map type filtered by given keys.
|
||||
// Play: https://go.dev/play/p/R1imbuci9qU
|
||||
func PickByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V {
|
||||
r := map[K]V{}
|
||||
for k, v := range in {
|
||||
if Contains(keys, k) {
|
||||
r[k] = 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](in map[K]V, values []V) map[K]V {
|
||||
r := map[K]V{}
|
||||
for k, v := range in {
|
||||
if Contains(values, v) {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// OmitBy returns same map type filtered by given predicate.
|
||||
// Play: https://go.dev/play/p/EtBsR43bdsd
|
||||
func OmitBy[K comparable, V any](in map[K]V, predicate func(K, V) bool) map[K]V {
|
||||
r := map[K]V{}
|
||||
for k, v := range in {
|
||||
if !predicate(k, v) {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
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](in map[K]V, keys []K) map[K]V {
|
||||
r := map[K]V{}
|
||||
for k, v := range in {
|
||||
if !Contains(keys, k) {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
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](in map[K]V, values []V) map[K]V {
|
||||
r := map[K]V{}
|
||||
for k, v := range in {
|
||||
if !Contains(values, v) {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
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))
|
||||
|
||||
@ -36,7 +111,15 @@ func Entries[K comparable, V any](in map[K]V) []Entry[K, V] {
|
||||
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 := map[K]V{}
|
||||
|
||||
@ -47,7 +130,29 @@ func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V {
|
||||
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 := map[V]K{}
|
||||
|
||||
for k, v := range in {
|
||||
out[v] = k
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// Assign merges multiple maps from left to right.
|
||||
// Play: https://go.dev/play/p/VhwfJOyxf5o
|
||||
func Assign[K comparable, V any](maps ...map[K]V) map[K]V {
|
||||
out := map[K]V{}
|
||||
|
||||
@ -60,7 +165,20 @@ func Assign[K comparable, V any](maps ...map[K]V) map[K]V {
|
||||
return out
|
||||
}
|
||||
|
||||
// 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(V, K) R) map[R]V {
|
||||
result := map[R]V{}
|
||||
|
||||
for k, v := range in {
|
||||
result[iteratee(v, k)] = v
|
||||
}
|
||||
|
||||
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(V, K) R) map[K]R {
|
||||
result := map[K]R{}
|
||||
|
||||
@ -69,4 +187,16 @@ func MapValues[K comparable, V any, R any](in map[K]V, iteratee func(V, K) R) ma
|
||||
}
|
||||
|
||||
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(K, V) R) []R {
|
||||
result := make([]R, 0, len(in))
|
||||
|
||||
for k, v := range in {
|
||||
result = append(result, iteratee(k, v))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user