Skip to content

Instantly share code, notes, and snippets.

@wilk
Created March 26, 2020 17:14
Show Gist options
  • Save wilk/ef8676ac5b0e8398a527f7f1a299c3c1 to your computer and use it in GitHub Desktop.
Save wilk/ef8676ac5b0e8398a527f7f1a299c3c1 to your computer and use it in GitHub Desktop.
function InMemoryStorage() {
return {
store: <T>(): Map<string, T> => new Map(),
set: <T>(key: string, value: T) => (store: Map<string, T>) => store.set(key, value),
get: <T>(key: string) => (store: Map<string, T>): T => store.get(key),
};
}
const storage = InMemoryStorage();
const store = storage.store();
storage.set<number>('a', 10)(store);
const val = storage.get<number>('a')(store);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment