Apply a callback to an array: Difference between revisions

no edit summary
No edit summary
Line 1,143:
 
</lang>
 
=={{header|Order}}==
Both sequences and tuples support the usual map operation seen in many functional languages. Sequences also support <code>8seq_for_each</code>, and a few variations, which returns <code>8nil</code>.
<lang c>#include <order/interpreter.h>
 
ORDER_PP( 8tuple_map(8fn(8X, 8times(8X, 8X)), 8tuple(1, 2, 3, 4, 5)) )
// -> (1,4,9,16,25)
 
ORDER_PP( 8seq_map(8fn(8X, 8times(8X, 8X)), 8seq(1, 2, 3, 4, 5)) )
// -> (1)(4)(9)(16)(25)
 
ORDER_PP( 8seq_for_each(8fn(8X, 8print(8X 8comma)), 8seq(1, 2, 3, 4, 5)) )
// prints 1,2,3,4,5, and returns 8nil</lang>
 
=={{header|Oz}}==
Anonymous user