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

Document Qo::PatternMatchers::PatternMatch#default as private API #25

Closed
wants to merge 1 commit into from

Conversation

bolshakov
Copy link
Contributor

I want my Option matcher raise error if nothing matcher instead of returning nil (because the whole point of having Option is to avoid dealing with nils.

I managed to achieve this by redefining @default ivar but not really happy with using undocumented internals:

  module ExhaustivePatternMatch
    def initialize(**)
      super
      @default ||= self.else { fail MatchError }
    end
  end

So, I documented PatternMatch#default accessor as private API to make it valid extension point.

@baweaver
Copy link
Owner

I'd had an idea earlier to mark branches as required. Perhaps I'll look into implementing that back in, as I feel that'd be a more explicit way to do it.

@bolshakov
Copy link
Contributor Author

Required branch is not the same. For example this matcher doesn't require else branch

option.match do |m|
  m.some { |x| x * 2 }
  m.none { 'noop' }
end

I want to customise behaviour if nothing matched

@baweaver baweaver mentioned this pull request Feb 18, 2019
@baweaver
Copy link
Owner

#26 addresses some of this.

@bolshakov bolshakov closed this Feb 19, 2019
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