lib/fluxo/result.rb in fluxo-0.2.0 vs lib/fluxo/result.rb in fluxo-0.2.1

- old
+ new

@@ -1,11 +1,10 @@ # frozen_string_literal: true module Fluxo class Result - attr_reader :operation, :type, :value - attr_accessor :ids + attr_reader :operation, :type, :value, :ids # @param options [Hash] # @option options [Fluxo::Operation] :operation The operation instance that gererated this result # @option options [symbol] :type The type of the result. Allowed types: :ok, :failure, :exception # @option options [Any] :value The value of the result. @@ -14,9 +13,18 @@ @operation = operation @value = value @type = type @ids = Array(ids) end + + def mutate(**attrs) + self.class.new(**{operation: operation, type: type, value: value, ids: ids}.merge(attrs)) + end + + def ==(other) + other.is_a?(self.class) && other.operation == operation && other.type == type && other.value == value && other.ids == ids + end + alias_method :eql?, :== # @return [Boolean] true if the result is a success def success? type == :ok end