Unlike for \clist_map_inline:nn
the second argument to the _map_token:nn
functions (the same is true for e.g. \prop_map_tokens:Nn
etc.) is not a definition for an internal macro, instead it should be called with some tokens in the second argument which expect a following brace group containing the list item. For instance, the following just outputs every item:
\clist_map_tokens:nn { a, b, c } { \use:n }
This is useful if your code needs another argument which just gets forwarded. For instance, what if we want to output only the numeric items in a clist which are bigger than another given number? You could achieve this fully expandable with the following function (that you could then nest in the argument of another clist function with an e
-type expansion):
\documentclass[]{article}
\ExplSyntaxOn
\cs_new:Npn \mymodule_filter_numbers:nn #1#2
{
\clist_if_empty:nF {#2}
{
\exp_args:Ne \exp_not:o
{
\exp_not:N \use_none:n
\clist_map_tokens:nn {#2} { \__mymodule_filter_numbers:nn {#1} }
}
}
}
\cs_new:Npn \__mymodule_filter_numbers:nn #1#2
{
\int_compare:nT { (#2) #1 } { , { \exp_not:n {#2} } }
}
\NewExpandableDocumentCommand \filternumbers { m m }
{
\mymodule_filter_numbers:nn {#1} {#2}
}
\ExplSyntaxOff
\edef\foo{\filternumbers{>5}{1,2,3,4,5,6,7,8,9}}\show\foo
\begin{document}
\filternumbers{>5}{1,2,3,4,5,6,7,8,9}
\end{document}