Sha256: e7ff508cb91dee50529f0a76d0f385fe27605ba56cae4f80d6b98df4cd1a4ea8

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 Bytes

Contents

# frozen_string_literal: true

module Kind
  module Maybe
    module Wrappable
      def wrap(arg = UNDEFINED)
        if block_given?
          begin
            return new(yield) if UNDEFINED == arg

            input = __call_before_expose_the_arg_in_a_block(arg)

            input.kind_of?(Maybe::None) ? input : new(yield(input))
          rescue StandardError => exception
            Maybe.__none__(exception)
          end
        else
          return new(arg) if UNDEFINED != arg

          WRONG_NUMBER_OF_ARGS.error!(given: 0, expected: 1)
        end
      end

      private

        def __call_before_expose_the_arg_in_a_block(input)
          input
        end
    end

    private_constant :Wrappable
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kind-4.1.0 lib/kind/maybe/wrappable.rb