Sha256: 2480fd568507f249cdbaf88e281b061210fb0c4540b240e93572d5645faec7ae

Contents?: true

Size: 560 Bytes

Versions: 13

Compression:

Stored size: 560 Bytes

Contents

module SoberSwag
  module Nodes
    ##
    # Root node of the tree
    class Primitive < Base
      def initialize(value, metadata = {})
        @value = value
        @metadata = metadata
      end

      attr_reader :value, :metadata

      def map(&block)
        self.class.new(block.call(value))
      end

      def deconstruct
        [value, metadata]
      end

      def deconstruct_keys(_)
        { value: value, metadata: metadata }
      end

      def cata(&block)
        block.call(self.class.new(value, metadata))
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sober_swag-0.14.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.13.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.12.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.11.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.10.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.9.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.8.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.7.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.6.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.5.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.4.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.3.0 lib/sober_swag/nodes/primitive.rb
sober_swag-0.2.0 lib/sober_swag/nodes/primitive.rb