main
1using System;
2
3namespace jive
4{
5 static public class FuncExtensions
6 {
7 static public readonly object mutex = new object();
8
9 static public Func<T> memoize<T>(this Func<T> item) where T : class
10 {
11 T the_implementation = null;
12 return () =>
13 {
14 if (null == the_implementation)
15 {
16 lock (mutex)
17 {
18 if (null == the_implementation)
19 {
20 the_implementation = item();
21 }
22 }
23 }
24 return the_implementation;
25 };
26 }
27 }
28}