Skip to content

Commit a304ef3

Browse files
Add HashMap.toValues
1 parent 18f0eef commit a304ef3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/effect/src/HashMap.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ export const keySet: <K, V>(self: HashMap<K, V>) => HashSet<K> = keySet_.keySet
229229
*/
230230
export const values: <K, V>(self: HashMap<K, V>) => IterableIterator<V> = HM.values
231231

232+
/**
233+
* Returns an `Array` of the values within the `HashMap`.
234+
*
235+
* @since 3.13.0
236+
* @category getters
237+
*/
238+
export const toValues = <K, V>(self: HashMap<K, V>): Array<V> => Array.from(values(self))
239+
232240
/**
233241
* Returns an `IterableIterator` of the entries within the `HashMap`.
234242
*

packages/effect/test/HashMap.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ describe("HashMap", () => {
395395
deepStrictEqual(result, [value("a"), value("b")])
396396
})
397397

398+
it("toValues", () => {
399+
const map = HM.make([key(0), value("a")], [key(1), value("b")])
400+
const result = HM.toValues(map)
401+
402+
deepStrictEqual(result, [value("a"), value("b")])
403+
})
404+
398405
it("entries", () => {
399406
const map = HM.make([key(0), value("a")], [key(1), value("b")])
400407
const result = Array.from(HM.entries(map))

0 commit comments

Comments
 (0)