<commit_before>module Transproc
  module Conditional
    module_function

    def guard(value, predicate, fn)
      predicate[value] ? fn[value] : value
    end

    Transproc.register_from(self)
  end
end<commit_msg>Add docs to transproc/conditional [ci skip]<commit_after>module Transproc

  # Conditional transformation functions
  #
  # @example
  #   require 'transproc/conditional'
  #
  #   include Transproc::Helper
  #
  #   fn = t(:guard, -> s { s.is_a?(::String) }, -> s { s.to_sym })
  #
  #   [fn[2], fn['Jane']]
  #   # => [2, :Jane]
  #
  # @api public
  module Conditional
    module_function

    # Apply the transformation function to subject if the predicate returns true, or return un-modified
    #
    # @example
    #   [2, 'Jane'].map do |subject|
    #     Transproc(:guard, -> s { s.is_a?(::String) }, -> s { s.to_sym })[subject]
    #   end
    #   # => [2, :Jane]
    #
    # @param [Mixed]
    #
    # @return [Mixed]
    #
    # @api public
    def guard(value, predicate, fn)
      predicate[value] ? fn[value] : value
    end

    Transproc.register_from(self)
  end
end
{'fraction_non_alphanumeric': 0.13793103448275862, 'fraction_numerical': 0.003629764065335753, 'mean_word_length': 2.6163934426229507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5368109', 'n_tokens_mistral': 393, 'n_tokens_neox': 379, 'n_words': 90}