Skip to content

Instantly share code, notes, and snippets.

Avatar

Gus guhou

View GitHub Profile
@guhou
guhou / sequence.ts
Created Mar 6, 2020
What is the name of this `unSequence` function?
View sequence.ts
export function sequence<T>(
map: Map<string, Promise<T>>
): Promise<Map<string, T>> {
return Promise.all(
Array.from(map, ([key, promisedValue]) =>
promisedValue.then<[string, T]>(value => [key, value])
)
).then((entries) => new Map(entries));
}
View gist:c43abfbd9780059615384bb617224591
### Keybase proof
I hereby claim:
* I am guhou on github.
* I am guhou (https://keybase.io/guhou) on keybase.
* I have a public key ASAZNEe0DRKu9xFDlHFgr6TGZPyE9zmMdBt86gMWZixpUQo
To claim this, I am signing this object:
@guhou
guhou / csharp-lists.md
Last active Sep 3, 2015 — forked from anonymous/csharp-lists.md
A brain-dump/introduction to Lists in C#
View csharp-lists.md

An introduction to generic Lists in C#

In this article I present an introduction to generic List types in the C# language. I assume an audience familiar with the principles of structured programming, including parameters, arrays and procedures, but with little experience with object-oriented programming. I will motivate an example for an encapsulated collection class, and then introduce generics as a means to improve our collection.

View Cache`1.cs
using System;
using System.Collections.Generic;
public class Cache<K, V> where V : class
{
private readonly Dictionary<K, WeakReference<V>> _data;
public Cache()
{
_data = new Dictionary<K, WeakReference<V>>();