<commit_before>require "spec_helper"
require "deterministic"
require "deterministic/core_ext/either"

describe Deterministic::CoreExt::Either do
  it "does something" do
    h = {}
    h.extend(Deterministic::CoreExt::Either)
    expect(h.success?).to be_falsey
    expect(h.failure?).to be_falsey
    expect(h.either?).to be_falsey
  end

  it "enables #success?, #failure?, #either? on all Objects" do
    ary = [Deterministic::Success(true), Deterministic::Success(1)]
    expect(ary.all?(&:success?)).to be_truthy

    ary = [Deterministic::Success(true), Deterministic::Failure(1)]
    expect(ary.all?(&:success?)).to be_falsey
    expect(ary.any?(&:failure?)).to be_truthy
  end

  it "allows using attempt_all on all Objects" do
    h = {a: 1}
    h.extend(Deterministic::CoreExt::Either)
    res = h.attempt_all do
      try { |s| self[:a] + 1}
    end<commit_msg>Update example to match README<commit_after>require "spec_helper"
require "deterministic"
require "deterministic/core_ext/either"

describe Deterministic::CoreExt::Either do
  it "does something" do
    h = {}
    h.extend(Deterministic::CoreExt::Either)
    expect(h.success?).to be_falsey
    expect(h.failure?).to be_falsey
    expect(h.either?).to be_falsey
  end

  it "enables #success?, #failure?, #either? on all Objects" do
    ary = [Deterministic::Success(true), Deterministic::Success(1)]
    expect(ary.all?(&:success?)).to be_truthy

    ary = [Deterministic::Success(true), Deterministic::Failure(1)]
    expect(ary.all?(&:success?)).to be_falsey
    expect(ary.any?(&:failure?)).to be_truthy
  end

  it "allows using attempt_all on all Objects" do
    h = {a: 1}
    h.extend(Deterministic::CoreExt::Either)
    res = h.attempt_all do
      try { |s| s[:a] + 1}
    end
{'fraction_non_alphanumeric': 0.14675767918088736, 'fraction_numerical': 0.004550625711035267, 'mean_word_length': 4.282282282282282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3425855', 'n_tokens_mistral': 670, 'n_tokens_neox': 609, 'n_words': 131}