Iterators: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added link to same fringe task) |
m (→{{header|Julia}}: linked list) |
||
Line 143: | Line 143: | ||
extensive set of functions which act on lists and vectors. Julia's Iterators can implement |
extensive set of functions which act on lists and vectors. Julia's Iterators can implement |
||
the C++ example: |
the C++ example: |
||
<lang julia> |
<lang julia>using DataStructures |
||
function PrintContainer(iterator) |
|||
iter = Iterators.Stateful(iterator) |
iter = Iterators.Stateful(iterator) |
||
foreach(x -> print(x, ", "), Iterators.take(iter, length(iter) -1)) |
foreach(x -> print(x, ", "), Iterators.take(iter, length(iter) -1)) |
||
Line 158: | Line 160: | ||
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] |
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] |
||
const colors = |
const colors = list("Red", "Orange", "Yellow", "Green", "Blue", "Purple") # this is a linked list |
||
println("All elements:") |
println("All elements:") |
||
Line 170: | Line 172: | ||
println("\nReverse first, fourth, and fifth elements:") |
println("\nReverse first, fourth, and fifth elements:") |
||
FirstFourthFifth(Iterators.reverse(days)) |
FirstFourthFifth(Iterators.reverse(days)) |
||
FirstFourthFifth(Iterators.reverse(colors)) |
FirstFourthFifth(Iterators.reverse(collect(colors))) |
||
</lang>{{out}} |
</lang>{{out}} |
||
<pre> |
<pre> |