Skip to content

Instantly share code, notes, and snippets.

View willbonney's full-sized avatar

Will willbonney

  • 00:58 (UTC -05:00)
View GitHub Profile
@willbonney
willbonney / gist:c6e81dbf6e670c50aa9136717c6ed042
Created February 13, 2026 00:11
Ungrouped element batching w/ predicate
export const batchMessages = <T,>(
messages: T[],
shouldBeBatched: (
prevItem: T,
nextItem: T,
) => boolean,
): T[][] =>
messages?.reduce((acc: T[][], curr) => {
const processed = acc.length
const prevSubArr = acc[processed - 1]