<commit_before><commit_msg>Use a popular memoisation class to explore the idea in trivial-rest.<commit_after>package trivial.rest.caching

// See http://stackoverflow.com/questions/25129721/scala-memoization-how-does-this-scala-memo-work

/**
 * Generic way to create memoized functions (even recursive and multiple-arg ones)
 *
 * @param f the function to memoize
 * @tparam I input to f
 * @tparam K the keys we should use in cache instead of I
 * @tparam O output of f
 */
case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
  import collection.mutable.{Map => Dict}
  val cache = Dict.empty[K, O]
  override def apply(x: I) = cache getOrElseUpdate (x, f(x))
}

object Memo {
  /**
   * Type of a simple memoized function e.g. when I = K
   */
  type ==>[I, O] = Memo[I, I, O]
}
{'fraction_non_alphanumeric': 0.13054499366286437, 'fraction_numerical': 0.010139416983523447, 'mean_word_length': 3.4886363636363638, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '6263242', 'n_tokens_mistral': 281, 'n_tokens_neox': 272, 'n_words': 97}