<commit_before>require 'spec_helper'

RSpec.describe Transducers do
  describe "mapping" do
    example do
      inc = ->(n){n+1}
      mapping_inc = Transducers.mapping(inc)
      append = ->(a,i){a << i}
      actual = [1,2,3].transduce(mapping_inc, append, [])
      expect(actual).to eq([2,3,4])
    end
  end

  describe "filtering" do
    example do
      even = ->(n){n.even?}
      filtering_evens = Transducers.filtering(even)
      append = ->(a,i){a << i}
      actual = [1,2,3,4,5].transduce(filtering_evens, append, [])
      expect(actual).to eq([2,4])
    end
  end

  describe "composing" do
    example do
      inc = ->(n){n+1}
      mapping_inc = Transducers.mapping(inc)
      even = ->(n){n.even?}
      filtering_evens = Transducers.filtering(even)
      append = ->(a,i){a << i}
      xform = Transducers.compose(mapping_inc, filtering_evens)
      actual = [1,2,3,4,5].transduce(xform, append, [])
      expect(actual).to eq([2,4,6])
    end
  end
end
<commit_msg>re-org examples<commit_after>require 'spec_helper'

RSpec.describe Transducers do
  let(:inc)    { ->(n){n + 1} }
  let(:even)   { ->(n){n.even?} }
  let(:append) { ->(a,i){a << i} }

  it "creates a mapping transducer" do
    mapping_inc = Transducers.mapping(inc)
    actual = [1,2,3].transduce(mapping_inc, append, [])
    expect(actual).to eq([2,3,4])
  end

  it "creates a filtering transducer" do
    filtering_evens = Transducers.filtering(even)
    actual = [1,2,3,4,5].transduce(filtering_evens, append, [])
    expect(actual).to eq([2,4])
  end

  it "composes transducers (or any fns, really)" do
    mapping_inc = Transducers.mapping(inc)
    filtering_evens = Transducers.filtering(even)
    xform = Transducers.compose(mapping_inc, filtering_evens)
    actual = [1,2,3,4,5].transduce(xform, append, [])
    expect(actual).to eq([2,4,6])
  end
end

{'fraction_non_alphanumeric': 0.16486486486486487, 'fraction_numerical': 0.024324324324324326, 'mean_word_length': 3.2946635730858467, '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': '1172257', 'n_tokens_mistral': 728, 'n_tokens_neox': 699, 'n_words': 134}