Module: Dry::Monads Private
- Extended by:
- Maybe::Mixin::Constructors, Result::Mixin::Constructors, Validated::Mixin::Constructors
- Includes:
- Core::Constants
- Defined in:
- lib/dry/monads.rb,
lib/dry/monads/do.rb,
lib/dry/monads/all.rb,
lib/dry/monads/try.rb,
lib/dry/monads/lazy.rb,
lib/dry/monads/list.rb,
lib/dry/monads/task.rb,
lib/dry/monads/unit.rb,
lib/dry/monads/curry.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/do/all.rb,
lib/dry/monads/errors.rb,
lib/dry/monads/result.rb,
lib/dry/monads/version.rb,
lib/dry/monads/do/mixin.rb,
lib/dry/monads/registry.rb,
lib/dry/monads/traverse.rb,
lib/dry/monads/constants.rb,
lib/dry/monads/validated.rb,
lib/dry/monads/transformer.rb,
lib/dry/monads/result/fixed.rb,
lib/dry/monads/right_biased.rb,
lib/json/add/dry/monads/maybe.rb,
lib/dry/monads/conversion_stubs.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Common, idiomatic monads for Ruby
Defined Under Namespace
Modules: ConversionStubs, Curry, Do, RightBiased, Transformer Classes: ConstructorNotAppliedError, InvalidFailureTypeError, Lazy, List, Maybe, Result, Task, Try, UnwrapError, Validated
Constant Summary collapse
- Unit =
Unit is a special object you can use whenever your computations don’t return any payload. Previously, if your function ran a side-effect and returned no meaningful value, you had to return things like Success(nil), Success([]), Success({}), Maybe(“”), Success(true) and so forth.
You should use Unit if you wish to return an empty monad.
::Object.new.tap do |unit| def unit.to_s "Unit" end def unit.inspect "Unit" end def unit.deconstruct EMPTY_ARRAY end unit.freeze end
- Some =
Maybe::Some
- None =
Maybe::None
- Success =
Result::Success
- Failure =
Result::Failure
- VERSION =
Gem version
"1.6.0"
- Traverse =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
List of default traverse functions for types. It is implicitly used by List#traverse for making common cases easier to handle.
{ Validated => -> el { el.alt_map(to_list) } }
- Valid =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Validated::Valid
- Invalid =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Validated::Invalid
Class Method Summary collapse
-
.[](*monads) ⇒ Module
Build a module with cherry-picked monads.
- .included(base) ⇒ Object
- .loader ⇒ Object private
-
.Result(error, **options) ⇒ Module
Creates a module that has two methods: ‘Success` and `Failure`.
Methods included from Maybe::Mixin::Constructors
Methods included from Result::Mixin::Constructors
Methods included from Validated::Mixin::Constructors
Class Method Details
.[](*monads) ⇒ Module
Build a module with cherry-picked monads. It saves a bit of typing when you add multiple monads to one class. Not loaded monads get loaded automatically.
68 69 70 71 72 73 74 75 |
# File 'lib/dry/monads.rb', line 68 def self.[](*monads) monads.sort! @mixins.fetch_or_store(monads.hash) do monads.each { load_monad(_1) } mixins = monads.map { registry.fetch(_1) } ::Module.new { include(*mixins) }.freeze end end |
.included(base) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dry/monads.rb', line 31 def self.included(base) if all_loaded? base.include(*constructors) else raise "Load all monads first with require 'dry/monads/all'" end end |
.loader ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dry/monads.rb', line 16 def self.loader @loader ||= Zeitwerk::Loader.new.tap do |loader| root = File.("..", __dir__) loader.tag = "dry-monads" loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-monads.rb") loader.push_dir(root) loader.ignore( "#{root}/dry-monads.rb", "#{root}/dry/monads/{all,constants,errors,registry,version}.rb", "#{root}/json/**/*.rb" ) end end |
.Result(error, **options) ⇒ Module
Creates a module that has two methods: ‘Success` and `Failure`. `Success` is identical to Dry::Monads::Result::Mixin::Constructors#Success and Failure rejects values that don’t conform the value of the ‘error` parameter. This is essentially a Result type with the `Failure` part fixed.
397 398 399 |
# File 'lib/dry/monads/result.rb', line 397 def self.Result(error, **) Result::Fixed[error, **] end |