summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3kernel/l3seq.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-06-19 03:03:14 +0000
committerNorbert Preining <norbert@preining.info>2020-06-19 03:03:14 +0000
commitfa4840ca74917d6402885b9b77c26e51b61fc68a (patch)
treeefd50c9a9a8eddb4154175ae575aa5f435582a06 /macros/latex/contrib/l3kernel/l3seq.dtx
parent7a78c3b8b21b6842d27bb48f37197f8c380ccc5e (diff)
CTAN sync 202006190303
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3seq.dtx')
-rw-r--r--macros/latex/contrib/l3kernel/l3seq.dtx66
1 files changed, 65 insertions, 1 deletions
diff --git a/macros/latex/contrib/l3kernel/l3seq.dtx b/macros/latex/contrib/l3kernel/l3seq.dtx
index 7b2121719d..40d829f96c 100644
--- a/macros/latex/contrib/l3kernel/l3seq.dtx
+++ b/macros/latex/contrib/l3kernel/l3seq.dtx
@@ -43,7 +43,7 @@
% }^^A
% }
%
-% \date{Released 2020-06-03}
+% \date{Released 2020-06-18}
%
% \maketitle
%
@@ -578,6 +578,26 @@
% \meta{items} are returned from left to right.
% \end{function}
%
+% \begin{function}[rEXP,added = 2018-05-03]{\seq_map_indexed_function:NN}
+% \begin{syntax}
+% \cs{seq_map_indexed_function:NN} \meta{seq~var} \meta{function}
+% \end{syntax}
+% Applies \meta{function} to every entry in the \meta{sequence
+% variable}. The \meta{function} should have signature |:nn|. It
+% receives two arguments for each iteration: the \meta{index} (namely
+% |1| for the first entry, then |2| and so on) and the \meta{item}.
+% \end{function}
+%
+% \begin{function}[added = 2018-05-03]{\seq_map_indexed_inline:Nn}
+% \begin{syntax}
+% \cs{seq_map_indexed_inline:Nn} \meta{seq~var} \Arg{inline function}
+% \end{syntax}
+% Applies \meta{inline function} to every entry in the \meta{sequence
+% variable}. The \meta{inline function} should consist of code which
+% receives the \meta{index} (namely |1| for the first entry, then |2|
+% and so on) as~|#1| and the \meta{item} as~|#2|.
+% \end{function}
+%
% \begin{function}[rEXP, updated = 2012-06-29]{\seq_map_break:}
% \begin{syntax}
% \cs{seq_map_break:}
@@ -2018,6 +2038,50 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}
+% {
+% \seq_map_indexed_function:NN, \seq_map_indexed_inline:Nn,
+% \@@_map_indexed:nNN, \@@_map_indexed:Nw
+% }
+% Similar to \cs{seq_map_function:NN} but we keep track of the item
+% index as a |;|-delimited argument of \cs{@@_map_indexed:Nw}.
+% \begin{macrocode}
+\cs_new:Npn \seq_map_indexed_function:NN #1#2
+ {
+ \@@_map_indexed:NN #1#2
+ \prg_break_point:Nn \seq_map_break: { }
+ }
+\cs_new_protected:Npn \seq_map_indexed_inline:Nn #1#2
+ {
+ \int_gincr:N \g__kernel_prg_map_int
+ \cs_gset_protected:cpn
+ { @@_map_ \int_use:N \g__kernel_prg_map_int :w } ##1##2 {#2}
+ \exp_args:NNc \@@_map_indexed:NN #1
+ { @@_map_ \int_use:N \g__kernel_prg_map_int :w }
+ \prg_break_point:Nn \seq_map_break:
+ { \int_gdecr:N \g__kernel_prg_map_int }
+ }
+\cs_new:Npn \@@_map_indexed:NN #1#2
+ {
+ \exp_after:wN \@@_map_indexed:Nw
+ \exp_after:wN #2
+ \int_value:w 1
+ \exp_after:wN \use_i:nn
+ \exp_after:wN ;
+ #1
+ \prg_break: \@@_item:n { } \prg_break_point:
+ }
+\cs_new:Npn \@@_map_indexed:Nw #1#2 ; #3 \@@_item:n #4
+ {
+ #3
+ #1 {#2} {#4}
+ \exp_after:wN \@@_map_indexed:Nw
+ \exp_after:wN #1
+ \int_value:w \int_eval:w 1 + #2 ;
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\seq_count:N, \seq_count:c}
% \begin{macro}{\@@_count:w, \@@_count_end:w}
% Since counting the items in a sequence is quite common, we optimize