Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid running success results after end_line #15

Conversation

sullyvannunes
Copy link

This PR introduces the concept of End Line to address issue #14. End Line is intended to be a playful term that evokes the Railway.

The method and_then checks whether the current result is an End Line rather than solely checking for failure.

When to Set End Line for a Result?

  • Failure is always treated as an End Line. Therefore, it doesn`t alter the behavior for failures.

  • Success is considered an End Line if and only if a Continue result produces a Success result. Consequently, the and_then method will not execute blocks for success results marked as End Line, returning the first Success found after a Continue. For example:

class BCDD::Result::Context::AndThenWithSubjectContinueFollowedBySuccessResultsSingletonTest < Minitest::Test
  module ContinuedFollowedBySuccessResults
    extend self, BCDD::Result.mixin(with: :Continue)

    def call
      Continue(value: 0)
        .and_then { Success(:first_success, value: 1) }
        .and_then { Success(:second_success, value: 2) }
    end
  end

  test 'Method chain interrupts after the first Success' do
    success = ContinuedFollowedBySuccessResults.call

    assert_predicate success, :success?
    assert_equal :first_success, success.type
    assert_equal({ value: 1 }, success.value)
  end
end

To-Do

  • Discuss whether it makes sense to raise an error when attempting to execute and_then blocks and methods inSuccess End Line. Otherwise, debugging a long and_then chain may become challenging.
  • Update the documentation in accordance with the previous discussion.

@serradura
Copy link
Member

@sullyvannunes, thank you for your contribution!

The last release (which introduced the BCDD::Result::Config changed the structure and made it challenging to reuse what you proposed. Because of this, I decided to implement the feature from scratch in a new branch (#17). And as it was merged, I'll close your PR.

Thank you again for your time and interest in contributing to the gem!

@serradura serradura closed this Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants