<commit_before>package me.stockwells.util.cache;

import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Function;

import static com.google.common.base.Preconditions.checkNotNull;

@ParametersAreNonnullByDefault
public class CacheLoaders {

	public static <K, V> CacheLoader<K, V> from(LoadingCache<K, V> loadingCache) {
		return from(k -> {
			return loadingCache.getUnchecked(checkNotNull(k));
		});
	}

	public static <K, V> CacheLoader<K, V> from(Function<K, V> function) {
		return new FunctionToCacheLoader<>(function);
	}

	private static final class FunctionToCacheLoader<K, V> extends CacheLoader<K, V> {
		private final Function<K, V> computingFunction;

		FunctionToCacheLoader(Function<K, V> computingFunction) {
			this.computingFunction = checkNotNull(computingFunction);
		}

		@Override
		public V load(K key) {
			return computingFunction.apply(checkNotNull(key));
		}
	}


}
<commit_msg>Cleaned up CacheLoaders util class<commit_after>package me.stockwells.util.cache;

import com.google.common.base.Throwables;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Function;

import static com.google.common.base.Preconditions.checkNotNull;

@ParametersAreNonnullByDefault
public class CacheLoaders {
	public static <K, V> CacheLoader<K, V> fromFunction(Function<K, V> function) {
		return CacheLoader.from(function::apply);
	}

	public static <K, V> Function<K, V> toFunction(CacheLoader<K,V> loader) {
		return key -> {
			try {
				return loader.load(key);
			} catch(Exception e) {
				throw Throwables.propagate(e);
			}
		};
	}
}

{'fraction_non_alphanumeric': 0.11235326998323085, 'fraction_numerical': 0.0, 'mean_word_length': 5.415770609318996, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4263022', 'n_tokens_mistral': 597, 'n_tokens_neox': 559, 'n_words': 119}