public static < T > Supplier < T > memoized ( Supplier < T > actual ) { return new Supplier < T > ( ) { Supplier < T > delegate = this :: initialize ; boolean initialized ; public T get ( ) { return delegate . get ( ) ; } private synchronized T initialize ( ) { if ( ! initialized ) { T value = actual . get ( ) ; delegate = ( ) -> value ; initialized = true ; } return delegate . get ( ) ; } } ; }
Caches the result of supplier in a thread safe manner .