Is there some direct and simple "cyclic Take", sometimes also known as "overtake" in Mathematica. That is, if the take specification runs out of elements, it just cycles back to the beginning (as many times as necessary).
For example, if the functions were named OverTake
, then:
OverTake[{1, 2}, 5]
(* {1, 2, 1, 2, 1} *)
(This would be a direct analog of the take functions in the array-processing languages APL and J.)
I can clumsily code a function to do that, but I was hoping for a simple use of something built in.
PadRight[{}, 5, {1, 2}]
? $\endgroup$Take
usage when requesting fewer elements than the length of the list. Please post it as an answer! $\endgroup$"Periodic"
withPadRight
in the other answer, I don't see why it shouldn't be preserved here as well. $\endgroup$