public static < T > Predicate < T > memoizePredicate ( final Predicate < T > p , final Cacheable < Boolean > cache ) { final Function < T , Boolean > memoised = memoizeFunction ( ( Function < T , Boolean > ) t -> p . test ( t ) , cache ) ; LazyImmutable < Boolean > nullR = LazyImmutable . def ( ) ; return ( t ) - > t == null ? nullR . computeIfAbsent ( ( ) -> p . test ( null ) ) : memoised . apply ( t ) ; }
Convert a Predicate into one that caches it s result