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

     1  // Package convert provides key, value convert adapters
     2  package convert
     3  
     4  // Key adapts a key converter to the key/value converter that converts only keys
     5  func Key[V, K, KOUT any](converter func(K) (KOUT, error)) (out func(key K, val V) (KOUT, V, error)) {
     6  	return func(key K, val V) (KOUT, V, error) {
     7  		k, err := converter(key)
     8  		return k, val, err
     9  	}
    10  }
    11  
    12  // Value adapts a value converter to the key/value converter that converts only values
    13  func Value[K, V, VOUT any](converter func(V) (VOUT, error)) (out func(key K, val V) (K, VOUT, error)) {
    14  	return func(key K, val V) (K, VOUT, error) {
    15  		v, err := converter(val)
    16  		return key, v, err
    17  	}
    18  }