<commit_before>#pragma once
#include <core/future.hh>
namespace smf {

/// brief - generic filter interface (c++ conept'ish) that gets
/// applied from the server and client(todo) before and after a request
///
template <typename T> struct rpc_filter { future<T> operator()(T t); };


/// brief - applies a function future<T> apply(T &&t); to all the filters
/// useful for incoming and outgoing filters. Taking a pair of iterators to
/// unique ptrs. see incoming_filter.h and outgoing_filter.h
/// for details
///
template <typename Iterator, typename Arg, typename... Ret>
future<Ret...>
rpc_filter_apply(const Iterator &b, const Iterator &end, Arg &&arg) {
  auto begin = b;
  if(begin == end) {
    return make_ready_future<Ret...>(std::forward<Arg>(arg));
  }
  return (*begin)(std::forward<Arg>(arg))
    .then([begin = std::next(begin), end](Arg && a) {
      return rpc_filter_apply<Iterator, Arg, Ret...>(begin, end,
                                                     std::forward<Arg>(a));
    });
}

template <class Container, typename Arg>
future<Arg> rpc_filter_apply(Container &c, Arg &&arg) {
  return rpc_filter_apply<typename Container::iterator, Arg, Arg>(<commit_msg>comments: fix comments and docs for rpc_filter.h<commit_after>#pragma once
#include <core/future.hh>
namespace smf {

/// brief - generic filter interface (c++ conept'ish) that gets
/// applied from the server and client(todo) before and after a request
///
template <typename T> struct rpc_filter { future<T> operator()(T t); };


/// brief - applies a functor `future<T> operator()(T t)` to all the filters
/// useful for incoming and outgoing filters. Taking a pair of iterators
///
template <typename Iterator, typename Arg, typename... Ret>
future<Ret...>
rpc_filter_apply(const Iterator &b, const Iterator &end, Arg &&arg) {
  auto begin = b;
  if(begin == end) {
    return make_ready_future<Ret...>(std::forward<Arg>(arg));
  }
  return (*begin)(std::forward<Arg>(arg))
    .then([begin = std::next(begin), end](Arg && a) {
      return rpc_filter_apply<Iterator, Arg, Ret...>(begin, end,
                                                     std::forward<Arg>(a));
    });
}

template <class Container, typename Arg>
future<Arg> rpc_filter_apply(Container &c, Arg &&arg) {
  return rpc_filter_apply<typename Container::iterator, Arg, Arg>(
{'fraction_non_alphanumeric': 0.1481164383561644, 'fraction_numerical': 0.0, 'mean_word_length': 3.4770114942528734, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7109631', 'n_tokens_mistral': 705, 'n_tokens_neox': 691, 'n_words': 224}