Uses for MapAll ( //@ )

后端 未结 4 1684
Happy的楠姐
Happy的楠姐 2021-01-02 05:07

The function MapAll was seen as important enough to warrant the short form //@, yet I rarely use it, especially compared to others like /@

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 05:34

    I don't use it, but has some fun behavior for Listable functions. For example:

    If you want each element in a list to have a function applied to it a number of times depending on its nested depth in the list, I guess this the only time I've seen it used.

    SetAttributes[f, Listable]
    
    (f //@ {{a}, {{b}}, c}) // Flatten
    
        {f[f[f[a]]], f[f[f[f[b]]]], f[f[c]]}

    Generally though I would imagine you could use ReplaceAll whenever you would use this.

提交回复
热议问题