Sha256: 6136d9526f656432d6e97fa9dd1acda87095af5c93043e2086c7f41fe93d819e

Contents?: true

Size: 919 Bytes

Versions: 2

Compression:

Stored size: 919 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 success outcomes.
    class Succeed < NullaryRelation
      include Singleton

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

      # Returns a Fiber-like object (a DuckFiber).
      # When that object receives the message resume, it will
      # return a success 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)
        # Important: every `solver_for` call will result in a distinct Context.
        DuckFiber.new(-> { ctx.succeeded! })
      end
    end # class
  end # module
end # module

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mini_kraken-0.3.03 lib/mini_kraken/core/succeed.rb
mini_kraken-0.3.02 lib/mini_kraken/core/succeed.rb