How to add group function to Array method?

I wanna use function following like, a_list_of_something.group(by: x => x.at(1)), which works as group_by in js world

#let group(ts, by: x=>x) = ts.fold((), (grps, t) => {
  let not_new = grps.any(grp => by(grp.first()) == by(t))
  if not_new { grps.map(grp => { if by(grp.first()) == by(t) { (t, ..grp) }
    else { grp } }) }
  else { (..grps, (t,),) } })

How to add a group method to Array class

You cannot modify methods available on built-in types