Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There definitely are valid use cases for a Map, and even more now that we have WeakMaps (e.g. associating data DOM nodes). Or mapping functions to values, e.g. something like this:

  const returnCache = new Map<() => any, any>()

  const memoized = <T extends () => any>(f: T): ReturnType<T> => {
    if (returnCache.has(f)) return returnCache.get(f)
    const v = f()
    returnCache.set(f, v)
    return v
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: