Implement ASTIndexBy using reduce