/** * Maps over the entries of the `HashMap` using the specified partial function * and filters out `None` values. * * @tsplus static HashMap.Aspects collectWithIndex * @tsplus pipeable HashMap collectWithIndex */ export function collectWithIndex(f: (k: K, a: A) => Maybe) { return (self: HashMap): HashMap => { const m = HashMap.empty() return m.mutate((m) => { for (const [k, a] of self) { const o = f(k, a) if (o.isSome()) { m.set(k, o.value) } } }) } }