<commit_before>module Monadic
  class Maybe 
    include Monadic::Monad
    
    def self.unit(value)
      return Nothing if value.nil? || (value.respond_to?(:empty?) && value.empty?)
      return Just.new(value)
    end

    # Initialize is private, because it always would return an instance of Maybe, but Just or Nothing 
    # are required (Maybe is abstract).
    private_class_method :new

    # @return true if the underlying object responds to #empty?, false otherwise
    def empty?
      @value.respond_to?(:empty?) && @value.empty?
    end

    # @return [Failure, Success] the Maybe Monad filtered with the block or proc expression
    def select(proc = nil, &block)
      func = (proc || block)
      return Maybe(@value.select {|v| func.call(v) }) if @value.respond_to? :select
      return Nothing unless func.call(@value)
      return self
    end

    def truly?
      @value == true
    end
  end

  # Represents an existing value
  class Just < Maybe
    public_class_method :new

    def fetch(default=nil)
      @value
    end
    alias :_ :fetch

    def method_missing(m, *args)
      Maybe(@value.__send__(m, *args))
    end

    def or(other)
      self
    end

    def to_s
      @value.to_s
    end
  end

  # Represents a NullObject
  class Nothing < Maybe
    class << self
      undef name

      def fetch(default=nil)
        return self if default.nil?
        return default
      end
      alias :_ :fetch

      def method_missing(m, *args)
        self
      end

      def or(other)
        Just(other)
      end

      def to_ary
        []
      end
      alias :to_a :to_ary

      def to_s
        'Nothing'
      end

      def truly?
        false
      end
    end
  end

  def Maybe(value)<commit_msg>Add implicit inspect for Maybe<commit_after>module Monadic
  class Maybe 
    include Monadic::Monad
    
    def self.unit(value)
      return Nothing if value.nil? || (value.respond_to?(:empty?) && value.empty?)
      return Just.new(value)
    end

    # Initialize is private, because it always would return an instance of Maybe, but Just or Nothing 
    # are required (Maybe is abstract).
    private_class_method :new

    # @return true if the underlying object responds to #empty?, false otherwise
    def empty?
      @value.respond_to?(:empty?) && @value.empty?
    end

    # @return [Failure, Success] the Maybe Monad filtered with the block or proc expression
    def select(proc = nil, &block)
      func = (proc || block)
      return Maybe(@value.select {|v| func.call(v) }) if @value.respond_to? :select
      return Nothing unless func.call(@value)
      return self
    end

    def truly?
      @value == true
    end
  end

  # Represents an existing value
  class Just < Maybe
    public_class_method :new

    def fetch(default=nil)
      @value
    end
    alias :_ :fetch

    def method_missing(m, *args)
      Maybe(@value.__send__(m, *args))
    end

    def inspect
      "Just(#{@value.inspect})"
    end

    def or(other)
      self
    end

    def to_s
      @value.to_s
    end
  end

  # Represents a NullObject
  class Nothing < Maybe
    class << self
      undef name

      def fetch(default=nil)
        return self if default.nil?
        return default
      end
      alias :_ :fetch

      def method_missing(m, *args)
        self
      end

      def or(other)
        Just(other)
      end

      def to_ary
        []
      end
      alias :to_a :to_ary

      def to_s
        'Nothing'
      end
      alias :inspect :to_s

      def truly?
        false
      end
    end
  end

  def Maybe(value)
{'fraction_non_alphanumeric': 0.08307863295359823, 'fraction_numerical': 0.0, 'mean_word_length': 2.0560271646859083, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1264152', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1067, 'n_words': 358}