Sha256: 583ce400ff6875e858308f1106eb6cbf96bd6ec500cc109112da4672ce76c96b

Contents?: true

Size: 726 Bytes

Versions: 4

Compression:

Stored size: 726 Bytes

Contents

# frozen_string_literal: true
module Zx
  module Maybe
    module Maybeable
      None = ->(*kwargs) { ::Maybe::None.new(*kwargs) }
      Some = ->(*kwargs) { ::Maybe::Some.new(*kwargs) }
      Maybe = ->(*kwargs) { ::Maybe.of(*kwargs) }
      
      def Maybe(*kwargs)
        ::Maybe.of(*kwargs)
      end
      
      def Some(*kwargs)
        ::Maybe::Some.new(*kwargs)
      end
  
      def None(*kwargs)
        ::Maybe::None.new(*kwargs)
      end

      def Try(default = nil, options = {})
        Some yield
      rescue StandardError => e
        None[default || options.fetch(:or, nil)]
      end
    end

    def self.included(klass)
      klass.include(Maybeable)
      klass.extend(Maybeable)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zx-monads-0.0.4 lib/zx/maybe.rb
zx-monads-0.0.3 lib/zx/maybe.rb
zx-monads-0.0.2 lib/zx/maybe.rb
zx-monads-0.0.1 lib/zx/maybe.rb