Home
dry-rb.org·1d
🔤Tokenization
Preview
Report Post

Safely and gracefully model complex transformations with monads, and use pattern matching to make robust error handling a first-class feature of your application.

Dry::Monads::Maybe(user).fmap(&:address).fmap(&:street)

# If user with address exists
# => Some("Street Address")

# If user or address is nil
# => None()

Safely model complex, chained transformations

class CreateArticle
include Dry::Monads[:result]
include Dry::Matcher.for(:call, with: Dry::Matcher::ResultMatcher)

def call(input)
if success?(input)
output = some_action(input)
Success(output)
else
Failure(input)
end
end
end

create = CreateArticle.new

create.(input) do |m|
m.success do |output|
# Handle success
end

m.failur...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help