Skip to main content
added 145 characters in body
Source Link
kglr
  • 403.4k
  • 18
  • 501
  • 959
ClearAll[mapThrough] mapThrough[funcs_List]mapThrough[a_List] := Map[Through @ funcsa @ ## &] 

or, as suggested by J.M. in comments,

mapThrough[a_] := Map @ Through @* a 

or

mapThrough = a |-> Map @ Through @* a 

Examples:

s2 = {{"h", "e", "l", "l", "o"}, {"d", "a", "y"}}; mapThrough[{StringJoin, Length}] @ s2 
{{"hello", 5}, {"day", 3}} 

Use with an arbitrary list of functions:

mapThrough[{StringReverse @* StringJoin, Reverse, First, Last, #[[{1, -1}]&}] @ s2 
{{"olleh", {"o", "l", "l", "e", "h"}, "h", "o", {"h", "o"}}, {"yad", {"y", "a", "d"}, "d", "y", {"d", "y"}}} 
ClearAll[mapThrough] mapThrough[funcs_List] := Map[Through @ funcs @ ## &] 

Examples:

s2 = {{"h", "e", "l", "l", "o"}, {"d", "a", "y"}}; mapThrough[{StringJoin, Length}] @ s2 
{{"hello", 5}, {"day", 3}} 

Use with an arbitrary list of functions:

mapThrough[{StringReverse @* StringJoin, Reverse, First, Last, #[[{1, -1}]&}] @ s2 
{{"olleh", {"o", "l", "l", "e", "h"}, "h", "o", {"h", "o"}}, {"yad", {"y", "a", "d"}, "d", "y", {"d", "y"}}} 
ClearAll[mapThrough] mapThrough[a_List] := Map[Through @ a @ ## &] 

or, as suggested by J.M. in comments,

mapThrough[a_] := Map @ Through @* a 

or

mapThrough = a |-> Map @ Through @* a 

Examples:

s2 = {{"h", "e", "l", "l", "o"}, {"d", "a", "y"}}; mapThrough[{StringJoin, Length}] @ s2 
{{"hello", 5}, {"day", 3}} 

Use with an arbitrary list of functions:

mapThrough[{StringReverse @* StringJoin, Reverse, First, Last, #[[{1, -1}]&}] @ s2 
{{"olleh", {"o", "l", "l", "e", "h"}, "h", "o", {"h", "o"}}, {"yad", {"y", "a", "d"}, "d", "y", {"d", "y"}}} 
Source Link
kglr
  • 403.4k
  • 18
  • 501
  • 959

ClearAll[mapThrough] mapThrough[funcs_List] := Map[Through @ funcs @ ## &] 

Examples:

s2 = {{"h", "e", "l", "l", "o"}, {"d", "a", "y"}}; mapThrough[{StringJoin, Length}] @ s2 
{{"hello", 5}, {"day", 3}} 

Use with an arbitrary list of functions:

mapThrough[{StringReverse @* StringJoin, Reverse, First, Last, #[[{1, -1}]&}] @ s2 
{{"olleh", {"o", "l", "l", "e", "h"}, "h", "o", {"h", "o"}}, {"yad", {"y", "a", "d"}, "d", "y", {"d", "y"}}}