Sha256: d6e35bed280093345af11750324a35b054f064541bb7cc5668857433a5e85c5a

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

module Monad
  module Maybe
    class Just < Base
      def initialize(value)
        @value = value
      end
  
      def method_missing(method, *args)
        value.send(method, *args).to_maybe
      end
  
      def unwrap(val)
        value
      end
  
      def nothing?
        false
      end

      def something?
        true
      end
  
      def just?
        true
      end

      def bind(fn)
        fn[@value].to_maybe
      end
  
      def nil?
        false
      end
  
      def ==(other)
        self === other || self.value == other
      end
  
      def ===(other)
        other.just? && self.value == other.value
      end
  
      def equal?(other)
        other.__id__ == self.__id__
      end
  
      def inspect
        "just(#{value.inspect})"
      end

      def to_s
        value.to_s
      end
      alias to_str to_s
  
      def to_a
        [self]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
monad-maybe-0.9.9 lib/monad/maybe/just.rb