Sha256: 7e785a8c82f4779b4edadf137ff1929cc6b42cb70367107c548d99d9a63611e4

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

# frozen_string_literal: true

module Fear
  module OptionApi
    # An +Option+ factory which creates +Some+ if the argument is
    # not +nil+, and +None+ if it is +nil+.
    # @param value [any]
    # @return [Fear::Option<any>]
    #
    # @example
    #   Fear.option(nil) #=> #<Fear::None>
    #   Fear.option(17) #=> #<Fear::Some get=17>
    #
    def option(value)
      if value.nil?
        none
      else
        some(value)
      end
    end

    # @return [Fear::None]
    # @example
    #   Fear.none #=> #<Fear::None>
    #
    def none
      Fear::None
    end

    # @param value [Object]
    # @return [Fear::Some]
    # @example
    #   Fear.some(17) #=> #<Fear::Some get=17>
    #   Fear.some(nil) #=> #<Fear::Some get=nil>
    #
    def some(value)
      Fear::Some.new(value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-3.0.0 lib/fear/option_api.rb