Sha256: 2dbd969094771dfc6b121452538ba59d43b75119f094f96e189403c5a61d0f5b

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

require 'singleton'
require_relative 'duck_fiber'
require_relative 'nullary_relation'

module MiniKraken
  module Core
    # A nullary relation that always returns a failure outcome.
    class Fail < NullaryRelation
      include Singleton

      # Constructor. Initialize the relation's name & freeze it...
      def initialize
        super('fail')
      end

      # Returns a Fiber-like object (a DuckFiber).
      # When that object receives the message resume, it will
      # signal a failure to the provided context.
      # @param _actuals [Array] MUST be empty array for nullary relation.
      # @param ctx [Core::Context] Runtime context
      # @return [Core::DuckFiber]
      def solver_for(_actuals, ctx)
        DuckFiber.new(-> { ctx.failed! })
      end
    end # class
  end # module
end # module

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mini_kraken-0.3.03 lib/mini_kraken/core/fail.rb
mini_kraken-0.3.02 lib/mini_kraken/core/fail.rb
mini_kraken-0.3.01 lib/mini_kraken/core/fail.rb
mini_kraken-0.3.00 lib/mini_kraken/core/fail.rb