Sha256: 142c5ca33b938228e558d3413f42d02c2bd7110acf1c8faf6f410e574fdb6488

Contents?: true

Size: 607 Bytes

Versions: 1

Compression:

Stored size: 607 Bytes

Contents

# frozen_string_literal: true
module Zx
  module Either
    module Eitherable
      Left = ->(*kwargs) { ::Either::Left.new(*kwargs) }
      Right = ->(*kwargs) { ::Either::Right.new(*kwargs) }
      
      def Right(*kwargs)
        ::Either::Right.new(*kwargs)
      end
  
      def Left(*kwargs)
        ::Either::Left.new(*kwargs)
      end

      def Try(default = nil, options = {})
        Right yield
      rescue StandardError => e
        Left default || options.fetch(:or, nil)
      end
    end
  
    def self.included(klass)
      klass.include(Eitherable)
    end
  end

  include Either
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zx-monads-0.0.1 lib/zx/either.rb