Skip to content

Instantly share code, notes, and snippets.

@ythirion
Created December 18, 2019 15:29
Show Gist options
  • Save ythirion/903b87d85c58436d91f1d8a551718560 to your computer and use it in GitHub Desktop.
Save ythirion/903b87d85c58436d91f1d8a551718560 to your computer and use it in GitHub Desktop.
memoization
static Func<string, string> GenerateGuidForUser = user => user + ":" + Guid.NewGuid();
static Func<string, string> GenerateGuidForUserMemoized = memo(GenerateGuidForUser);
[Fact]
public void memoization_example()
{
GenerateGuidForUserMemoized("spongebob");// spongebob:e431b439-3397-4016-8d2e-e4629e51bf62
GenerateGuidForUserMemoized("buzz");// buzz:50c4ee49-7d74-472c-acc8-fd0f593fccfe
GenerateGuidForUserMemoized("spongebob");// spongebob:e431b439-3397-4016-8d2e-e4629e51bf62
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment