elonzyy

15 Reputation

3 Badges

4 years, 95 days

MaplePrimes Activity


These are questions asked by elonzyy

Here is an example of map and flat_map in other scripting languages such as NodeJS:

 

let a = ['a', 'b', 'c']
a.map((e,i)=>[e,i])                    // returns: [['a', 0], ['b', 1], ['c', 2]]
a.flatMap((e,i) => e > 'b' ? [] : [e]) // returns: ['a', 'b']

 

What I do for map_with_index is:

 

map_with_index := (f, a) -> zip(f, to_list(a), [`$`(1..nops(to_list(a)))]);

 

My question is:

 

1) What is the canonical way to achieve map_with_index?

 

2) Is there a builtin procedure for flat_map? If not how to achieve it?

Page 1 of 1