Message details: group by send status, including viewed state
This commit is contained in:
parent
d91c336e62
commit
1e10286210
11 changed files with 380 additions and 248 deletions
26
ts/util/mapUtil.ts
Normal file
26
ts/util/mapUtil.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { reduce } from './iterables';
|
||||
|
||||
/**
|
||||
* Like Lodash's `groupBy`, but returns a `Map`.
|
||||
*/
|
||||
export const groupBy = <T, ResultT>(
|
||||
iterable: Iterable<T>,
|
||||
fn: (value: T) => ResultT
|
||||
): Map<ResultT, Array<T>> =>
|
||||
reduce(
|
||||
iterable,
|
||||
(result: Map<ResultT, Array<T>>, value: T) => {
|
||||
const key = fn(value);
|
||||
const existingGroup = result.get(key);
|
||||
if (existingGroup) {
|
||||
existingGroup.push(value);
|
||||
} else {
|
||||
result.set(key, [value]);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
new Map<ResultT, Array<T>>()
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue