# Little problem with Through

list = Partition[Range[20], 5, 5, 1, {}]

{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}

pos = Transpose[{Through[First, Last] /@ list, Through[Last, First] /@ list}]

{{1, 5}, {6, 10}, {11, 15}, {16, 20}}


As you see, I've used Through twice. I think once should be enough, but I haven't been able to see how to do it with one Through. Any ideas?

• Why not {First[#], Last[#]} & /@ list ? Commented Jun 12, 2013 at 6:09
• @b.gatessucks yes, me silly, haha, you can post that as one answer. Commented Jun 12, 2013 at 6:10
• To properly use Through[]: Through[{First, Last}[#]] & /@ list. Slot-free version: Composition[Through, {First, Last}] /@ list. Commented Jun 12, 2013 at 6:19
• Are you aware that you can do this with Part? list[[All,{1,-1}]] Commented Jun 12, 2013 at 7:45

I have tried this

list = Partition[Range[20], 5, 5, 1, {}];
Through[{First, Last}] /@ list
(* {Through[{First,Last}][{1,2,3,4,5}],Through[{First,Last}][{6,7,8,9,10}],
Through[{First,Last}][{11,12,13,14,15}],Through[{First,Last}][{16,17,18,19,20}]} *)


Let's see the example in help page of Through

Through[{f, g, h}[x]]
(* {f[x],g[x],h[x]} *)


as @0x4A4D metioned in the comment. We need one argument for

Through[{First, Last}[#]] & /@ list
(* {{1,5},{6,10},{11,15},{16,20}} *)


this is one error usage

Through[{f, g, h}][x]
(* Through[{f,g,h}][x] *)

Through[{f, g, h}[#]] &[x]
(* {f[x],g[x],h[x]} *)

• Well done. ${}$ Commented Jun 12, 2013 at 7:21
• Please don't make this an orgy of different formatting styles...
– rm -rf
Commented Jun 12, 2013 at 8:34
• @rm-rf hi,Do you mean the <kbd>tag? I'm learning format in SE, Do you think the hint word Output is necessary? Commented Jun 12, 2013 at 8:37
• @HyperGroups nice answer (+1). The <kbd> tag stands for keyboard, which is usually used for indicating a key on the keyboard, e.g., <kbd>Ctrl</kbd>. So it may not be a best choice for "Output". In fact, on this site, people usually just put the output results in blockquotes without any "hint word". Commented Jun 12, 2013 at 8:52
• @Silvia Ok, I learned that. Commented Jun 12, 2013 at 8:57