Singly-linked list/Traversal: Difference between revisions

Content added Content deleted
(→‎{{header|ooRexx}}: Add example for ooRexx)
Line 231: Line 231:


=={{header|Ela}}==
=={{header|Ela}}==
<lang ela>let traverse [] = []
<lang ela>traverse [] = []
traverse (x::xs) = x :: traverse xs</lang>
traverse (x::xs) = x :: traverse xs</lang>


This function traverses a list and constructs a new list at the same time. For a list in Ela it is the same as identity function, e.g. traverse [1,2,3] == [1,2,3]. However it can be useful in some cases. For example, to enforce a lazy list:
This function traverses a list and constructs a new list at the same time. For a list in Ela it is the same as identity function, e.g. traverse [1,2,3] == [1,2,3]. However it can be useful in some cases. For example, to enforce a lazy list:


<lang ela>let xs = [& x \\ x <- [1..1000]]//lazy list
<lang ela>xs = [& x \\ x <- [1..1000]]//lazy list


traverse xs</lang>
traverse xs</lang>