Skip to content

Commit

Permalink
ReadonlyMap: optimize traverseWithIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Mar 22, 2021
1 parent 1434fa5 commit ef6408e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ export const getTraversableWithIndex = <K>(O: Ord<K>): TraversableWithIndex2C<UR
const key = ks[i]
const a = ta.get(key)!
fm = F.ap(
F.map(fm, (m) => (b: B) => new Map(m).set(key, b)),
F.map(fm, (m) => (b: B) => m.set(key, b)),
f(key, a)
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/ReadonlyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,14 +914,14 @@ export const getTraversableWithIndex = <K>(O: Ord<K>): TraversableWithIndex2C<UR
F: Applicative<F>
): (<A, B>(ta: ReadonlyMap<K, A>, f: (k: K, a: A) => HKT<F, B>) => HKT<F, ReadonlyMap<K, B>>) => {
return <A, B>(ta: ReadonlyMap<K, A>, f: (k: K, a: A) => HKT<F, B>) => {
let fm: HKT<F, ReadonlyMap<K, B>> = F.of(empty)
let fm: HKT<F, Map<K, B>> = F.of(new Map())
const ks = keysO(ta)
const len = ks.length
for (let i = 0; i < len; i++) {
const key = ks[i]
const a = ta.get(key)!
fm = F.ap(
F.map(fm, (m) => (b: B) => new Map(m).set(key, b)),
F.map(fm, (m) => (b: B) => m.set(key, b)),
f(key, a)
)
}
Expand Down
1 change: 1 addition & 0 deletions test/ReadonlyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ describe('ReadonlyMap', () => {
])
)
)
U.deepStrictEqual(_.empty, new Map<never, never>())
})

it('wither', async () => {
Expand Down

0 comments on commit ef6408e

Please sign in to comment.