Sha256: 70ee3ed88a9fe044e800d7d40da0616d8aaaca3f0b120db9b6bac9c3091852cc

Contents?: true

Size: 630 Bytes

Versions: 11

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

module Kind
  module Maybe
    class Typed
      include Wrapper

      singleton_class.send(:alias_method, :[], :new)

      def initialize(kind)
        @kind = kind
      end

      def new(arg)
        value = Monad::Value[arg]

        @kind === value ? Maybe::Some[value] : Maybe::NONE_INSTANCE
      end

      alias_method :[], :new

      def inspect
        "Kind::Maybe<#{@kind}>"
      end

      private

        def __call_before_expose_the_arg_in_a_block(arg)
          value = Monad::Value[arg]

          @kind === value ? value : Maybe::NONE_INSTANCE
        end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
kind-5.10.0 lib/kind/maybe/typed.rb
kind-5.9.0 lib/kind/maybe/typed.rb
kind-5.8.1 lib/kind/maybe/typed.rb
kind-5.8.0 lib/kind/maybe/typed.rb
kind-5.7.0 lib/kind/maybe/typed.rb
kind-5.6.0 lib/kind/maybe/typed.rb
kind-5.5.0 lib/kind/maybe/typed.rb
kind-5.4.1 lib/kind/maybe/typed.rb
kind-5.4.0 lib/kind/maybe/typed.rb
kind-5.3.0 lib/kind/maybe/typed.rb
kind-5.2.0 lib/kind/maybe/typed.rb