Implementing Projection onto Isotypic Component of tensor power Let $ G $ be a finite group. Let $ D $ be a complex representation of $ G $. Let $ \rho $ be a complex irrep of $ G $. Then the orthogonal projector of the representation $ D $ onto the $ \rho $ isotypic component is given by
$$
P_\rho=\frac{dim(\rho)}{|G|}\sum_{g \in G} \overline{\chi_\rho(g)}D(g)
$$
Here the complex conjugate $ \overline{\chi_\rho(g)} $ can equivalently be written as $\chi_\rho(g^{-1}) $. And the dimension of the irrep $ dim(\rho) $ can equivalently be written as the character evaluated at the identity $ \chi_{\rho}(e) $. This formula for the projector onto the $ \rho $ isotypic component can be found for example here
Deriving the projection onto the isotypic component
here
Conceptual description of the isotypical component
and here
Central idempotent of a group representation
I am interested in the case where $ G $ is a finite matrix group and $ D $ is the $ n $th tensor power of the natural representation of $ G $. In that case the isotypic projector  for an irrep $ \rho $ is given by
$$
P_\rho=\frac{dim(\rho)}{|G|}\sum_{g \in G} \overline{\chi_\rho(g)}\;g^{\otimes n}
$$
Question: How do I calculate this projection matrix in GAP?
Pseudocode: (just an attempt)
(chi(I)/Size(G))* Sum(G,x->ComplexConjugate(chi(x))*TensorPower(x,n));
where chi  is the character of $ \rho $. Perhaps a better attempt breaks up the sum as
(chi(I)/Size(G))* Sum(ConjugacyClasses(G),x->ComplexConjugate(chi(x))*(Sum(ElementsOf(x),y->TensorPower(y,n)));
Bottom Line: I'm taking tensor powers of the natural representation of a finite matrix group. I want to look at the, 7th say, tensor power and find a basis for all irreducible subreps of a particular isomorphism type $ \rho $. I believe the best way to do this (with GAP or otherwise) is to use this projector formula. If there is a better way to find a basis for these subreps (maybe one that doesn't even use GAP!) feel free to suggest it.
 A: You are basically there, the only two changes I would do is to isolate the representation in an object (so the same code will work for other representations), and to respect that a character is given as an indexed list with positions corresponding to conjugacy classes.
Concretely (I'm picking $A_5$ in the permutation representation as random example of a matrix group):
gap> G:=AlternatingGroup(5);;
gap> C:=CharacterTable(G);;
gap> irrs:=Irr(C);;

We thus have the characters in correspondence to the conjugacy classes.
Since TensorPower is not a default library function, here is a way of building it:
TensorPower:=function(mat,n)
  return Iterated(ListWithIdenticalEntries(n,mat),KroneckerProduct);
end;

Next construct the representation as a homomorphism. I'm taking the 3rd tensor power of the permutation representation:
gap> repfct:=x->TensorPower(PermutationMat(x,5,Rationals),3);
function( x ) ... end
gap> imgs:=List(GeneratorsOfGroup(G),repfct);;
gap> rep:=GroupHomomorphismByFunction(G,Group(imgs),repfct);
MappingByFunction( Alt( [ 1 .. 5 ] ), <matrix group with
2 generators>, function( x ) ... end )

Now finally we can form the summation. We do this as a double sum, first summing over the indices of the conjugacy classes, and then over the elements of each class, starting with the trivial character:
gap> cl:=ConjugacyClasses(G);;
gap> chi:=irrs[1];;  # could take any other
gap> Length(cl);
5
proj:=Length(Image(rep,One(G)))/Size(G)*Sum([1..Length(cl)],
  i->GaloisCyc(chi[i],-1)*Sum(Elements(cl[i]),
      x->ImagesRepresentative(rep,x)));;

This returns a huge matrix. We can test for example its rank:
gap> RankMat(proj);
5

showing that the component for the trivial representation has dimension 5.
Similarly we find dimensions 18 (twice), 44, and 40 for the remaining irreducibles.
