Skip to content

Commit

Permalink
remove maybe implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrias committed Aug 21, 2024
1 parent 329d50e commit 82c6acc
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 547 deletions.
86 changes: 0 additions & 86 deletions lib/schema_registry/maybe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,92 +20,6 @@ module Maybe

Value = type_member(:out) { { upper: BasicObject } }

module ClassMethods
extend T::Sig
extend T::Helpers
abstract!

sig do
type_parameters(:Key)
.params(input: T::Hash[T.type_parameter(:Key), T.untyped])
.returns(T::Hash[T.type_parameter(:Key), T.untyped])
end
# You can use this method to easily transform a Hash with `Maybe` values into one without them,
# filtering out `Maybe` instances that are empty and unwrapping the present ones.
#
# Given a hash containing `Maybe` instances, returns a hash with only the values that are present.
# It also unwraps the present values.
#
# For convenience, it also recursively serializes nested T::Structs and strips nested hashes,
# arrays and sets.
#
# ```ruby
# Maybe.strip({ a: Maybe.from(1), b: Maybe.empty, c: Maybe.from(3) })
# # => { a: 1, c: 3 }
# ```
def self.strip(input) # rubocop:disable Metrics/PerceivedComplexity
input
.reject { |_key, value| value == empty }
.to_h do |key, value|
unwrapped = value.is_a?(Maybe::Present) ? value.value : value
enumerated =
if unwrapped.is_a?(Array) || unwrapped.is_a?(Set)
unwrapped.map { |v| v.is_a?(T::Struct) ? strip(v.serialize) : strip(v) }
else
unwrapped
end
serialized = enumerated.is_a?(T::Struct) ? enumerated.serialize : enumerated
stripped = serialized.is_a?(Hash) ? strip(serialized) : serialized

[key, stripped]
end
end

# Creates an empty instance.
sig { returns(Absent) }
def self.empty
Absent.new
end

sig { returns(Absent) }
# Creates an empty instance.
# Alias for self.empty
def self.none
empty
end

sig { returns(Absent) }
# Creates an empty instance.
# Alias for self.empty
def self.absent
empty
end

sig do
type_parameters(:Value)
.params(value: T.all(BasicObject, T.type_parameter(:Value)))
# .returns(Maybe[T.all(BasicObject, T.type_parameter(:Value))])
.returns(T.untyped)
end
# Creates an instance containing the specified value.
# Necessary to make this work with sorbet-coerce
def self.new(value)
from(value)
end

sig do
type_parameters(:Value)
.params(value: T.all(BasicObject, T.type_parameter(:Value)))
.returns(Maybe[T.all(BasicObject, T.type_parameter(:Value))])
end
# Creates an instance containing the specified value.
def self.from(value)
Present[T.all(BasicObject, T.type_parameter(:Value))].new(value)
end
end

mixes_in_class_methods(ClassMethods)

sig { abstract.returns(T::Boolean) }
# `true` if this `Maybe` contains a value, `false` otherwise.
def present?; end
Expand Down
81 changes: 0 additions & 81 deletions lib/schema_registry/maybe/absent.rb

This file was deleted.

96 changes: 0 additions & 96 deletions lib/schema_registry/maybe/present.rb

This file was deleted.

Loading

0 comments on commit 82c6acc

Please sign in to comment.