<commit_before>/**
 * @file
 */
#pragma once

namespace bi {
/**
 * Lambda function.
 */
template<class Type>
class Lambda {
public:
  typedef std::function<Type()> forward_type;
  typedef std::function<void(const Type&)> backward_type;

  /**
   * Constructor.
   */
  Lambda(const forward_type& forward = forward_type(),
      const backward_type& backward = backward_type()) :
      forward(forward),
      backward(backward) {
    //
  }

  /**
   * Evaluate forward lambda.
   */
  Type operator()() const {
    return forward();
  }

  /**
   * Evaluate backward lambda.
   */
  void operator()(const Type& o) const {
    return forward(o);
  }

private:
  /**
   * Forward lambda.
   */
  forward_type forward;

  /**
   * Backward lambda.
   */
  backward_type backward;
};
}<commit_msg>Added memoisation to lambdas.<commit_after>/**
 * @file
 */
#pragma once

namespace bi {
/**
 * Lambda function.
 */
template<class Type>
class Lambda {
public:
  typedef std::function<Type()> forward_type;
  typedef std::function<void(const Type&)> backward_type;

  /**
   * Constructor.
   */
  Lambda(const forward_type& forward = forward_type(),
      const backward_type& backward = backward_type()) :
      forward(forward),
      backward(backward),
      memoised(false) {
    //
  }

  /**
   * Evaluate forward lambda.
   */
  const Type& operator()() const {
    if (!memoised) {
      /* allow memoisation to occur while const, to keep invisible */
      auto self = const_cast<Lambda<Type>*>(this);
      self->value = forward();
      self->memoised = true;
    }
    return value;
  }

  /**
   * Evaluate backward lambda.
   */
  void operator()(const Type& o) const {
    backward(o);
  }

private:
  /**
   * Forward lambda.
   */
  forward_type forward;

  /**
   * Backward lambda.
   */
  backward_type backward;

  /**
   * Forward memoised value.
   */
  Type value;

  /**
   * Is the result of the forward lambda memoised?
   */
  bool memoised;
};
}
{'fraction_non_alphanumeric': 0.14510400811770674, 'fraction_numerical': 0.0, 'mean_word_length': 2.6051188299817185, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3700699', 'n_tokens_mistral': 643, 'n_tokens_neox': 631, 'n_words': 153}