Hyperlinkv0.8.0-beta.28

HashMap

HashMap.toEntriesconsteffect/HashMap.ts:661
<K, V>(self: HashMap<K, V>): Array<[K, V]>

Returns an Array<[K, V]> of the entries within the HashMap.

Example (Converting entries to an array)

import { HashMap } from "effect"

const gameScores = HashMap.make(
  ["alice", 1250],
  ["bob", 980],
  ["charlie", 1100]
)

// Convert to entries for processing
const scoreEntries = HashMap.toEntries(gameScores)

// Sort by score (descending)
const leaderboard = scoreEntries
  .sort(([, a], [, b]) => b - a)
  .map(([player, score], rank) => `${rank + 1}. ${player}: ${score}`)

console.log(leaderboard)
// ["1. alice: 1250", "2. charlie: 1100", "3. bob: 980"]

// Convert back to HashMap if needed
const sortedMap = HashMap.fromIterable(scoreEntries)
getters
Source effect/HashMap.ts:6611 lines
export const toEntries = <K, V>(self: HashMap<K, V>): Array<[K, V]> => Array.from(entries(self))
Referenced by 4 symbols