29 lines
		
	
	
		
			771 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			771 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package slices
 | 
						|
 | 
						|
func Of[T any](values ...T) []T {
 | 
						|
	return values
 | 
						|
}
 | 
						|
 | 
						|
// OfMap returns a slice containing the return values of the Unmapper
 | 
						|
// applied to any key-value pair in m
 | 
						|
// The order is random
 | 
						|
func OfMap[K comparable, V, T any](m map[K]V, unmapper MapUnmapper[K, V, T]) []T {
 | 
						|
	out := make([]T, 0, len(m))
 | 
						|
	for k, v := range m {
 | 
						|
		out = append(out, unmapper(k, v))
 | 
						|
	}
 | 
						|
	return out
 | 
						|
}
 | 
						|
 | 
						|
// UnmapKey is an Unmapper which returns the map key only
 | 
						|
// and discards its value. It is supposed to be used with OfMap
 | 
						|
func UnmapKey[K comparable, V any](key K, _ V) K {
 | 
						|
	return key
 | 
						|
}
 | 
						|
 | 
						|
// UnmapValue is an Unmapper which returns the map value only
 | 
						|
// and discards its key. It is supposed to be used with OfMap
 | 
						|
func UnmapValue[K comparable, V any](_ K, value V) V {
 | 
						|
	return value
 | 
						|
}
 |