github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/break/kv/predicate/api.go (about)

     1  // Package predicate provides helpers for filtering keys or values of a map
     2  package predicate
     3  
     4  // Key adapts a key appliable predicate to a key\value one
     5  func Key[V, K any](predicate func(K) (bool, error)) (out func(K, V) (bool, error)) {
     6  	if predicate != nil {
     7  		out = func(key K, _ V) (bool, error) { return predicate(key) }
     8  	}
     9  	return
    10  }
    11  
    12  // Value adapts a value appliable predicate to a key\value one
    13  func Value[K, V any](predicate func(V) (bool, error)) (out func(K, V) (bool, error)) {
    14  	if predicate != nil {
    15  		out = func(_ K, val V) (bool, error) { return predicate(val) }
    16  	}
    17  	return
    18  }