Q:

Is there a function that will transform the values of an association while deleting some that match a criteria?

I am looking for something better than
Select[Map[f,a],test]

As Map will work over the entire association (a) and then Select will work over all of the results. Something like
Cases[a,x_/;test[f[x]]:>f[x]]

But Cases only returns values (or functions of the values) not the keys.
I also tried
Map[If[test[#],#]&,a]

But it keeps the keys that fail the test and maps them to Null.
My sample association is
a = <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|>;

I would like to do something like
Select[Map[(3^#-2)&,a],PrimeQ]

Giving
<|b->7,d->79,e->241|>

My actual case is much more complicated but if I have a way to Map and Select in one pass for this case it will solve my more difficult problem.  Thanks!

A:

The use of AssociationMap solves the problem in this case as it can map all of the deleted cases to a single key-value pair that is easily removed or ignored.
a = AssociationMap[If[PrimeQ[x = (3^#[[2]] - 2)], #[[1]] -> x, "XXX" -> 0] &, a]

giving
<|XXX->0,b->7,d->79,e->241|>

Then, if needed
KeyDropFrom[a, "XXX"]

giving
<|b->7,d->79,e->241|>

Thanks for the suggestions.

A:

Association @ KeyValueMap[If[PrimeQ[3^#2 - 2], Nothing, #1 -> #2] &, a]

<|"b" -> 7, "d" -> 79, "e" -> 241|>

