Comments (9)
@korolvs oh, you're right and it's rather unexpected. I ditched inheritance completely that's why I haven't come across the issue. I'll fix it tomorrow since it'll require some testing before being sure it's fixed properly
from dry-monads.
Hi,
I have the similar error on github actions :LocalJumpError: no block given (yield)
When i run the CI on github actions, the keyword 'yield' by Dry monads not works. WHen I run locally all tests are ok. What is the reason?
from dry-monads.
It doesn't work for subclasses because .for
is not aware of them. If you want this, use the inherited
hook in the way described in the link you posted. Another solution is to go with the fully automated version of Do
, this will do the trick:
include Dry::Monads::Do
^it will wrap all the methods defined after this line, including subclasses
from dry-monads.
Thank you for the answer!
Did I understand the fully automated version correctly?
class BaseCommand
include Dry::Monads::Result::Mixin
include Dry::Monads::Do
def validate
Success(:ok)
end
end
class CreateCommand < BaseCommand
def call
yield validate
end
end
Doesn't work for me as well, I'll use another methods
from dry-monads.
Just a PSA for people who still get LocalJumpError: no block given (yield)
despite using include Dry::Monads::Do
:
Double-check that your base class isn't defining self.inherited
somewhere. I had code like this:
class MyBaseClass
include Dry::Monads[:result]
include Dry::Monads::Do
def.self.inherited(subclass)
...
end
end
class Subclass < MyBaseClass
def call
yield foobar
end
end
I was getting this issue until I found out Dry::Monads::Do::All
is doing some metaprogramming with self.inherited
: https://github.com/dry-rb/dry-monads/blob/master/lib/dry/monads/do/all.rb#L70
The fix was to call super
in self.inherited
on the base class, i.e.:
class MyBaseClass
include Dry::Monads[:result]
include Dry::Monads::Do
def.self.inherited(subclass)
super(subclass)
...
end
end
class Subclass < MyBaseClass
def call
yield foobar
end
end
from dry-monads.
@lcolombini pls ask questions on our forum (see contributing.md for the link). Please also attach example code that doesn't work, at least essential parts. Otherwise, I can't what's wrong.
from dry-monads.
@flash-gordon the sample is a classic dry-monads construct:
`def call
value = yield get_value_func
end
`
When I ran CI on GitHub, the error was LocalJumpError: no block given (yield), but I undestand the problem I the library Dry-Monads v1.4 in latest Ubuntu.
I'm developing on Mac OS and I don't have errors. I switched on Ubuntu machine for a trial and I replicated the issue. I solved back to v.1.3.5
from dry-monads.
I am getting the same result. In my case I am using docker, so we cannot update the library.
Ruby version:
- ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux-musl]
from dry-monads.
I ran into this when my code was inside an concerning(:name) do
block. Definitely unexpected behavior but not sure if there's an easy fix
from dry-monads.
Related Issues (20)
- Value constructors available globally HOT 4
- Spring (Rails pre-loader) and dry-monads are incompatible HOT 2
- Contrary to the doc comment, List#map might not return an array. HOT 6
- Fixed-Result resolution fails if first referenced by constant. HOT 1
- Support `#<=>` over Maybe HOT 3
- `include Dry::Monads[:do]` removes private method protection on instance methods HOT 2
- Do notation with block doesn't yield methods HOT 3
- `include Dry::Monads[:do]` doesn't work on class methods HOT 3
- Pattern Matching is broken for Array HOT 4
- Lazy.wait results in error
- Pattern matching `Success` containing an array returns a surprising result HOT 1
- Task#then alias for #bind conflicts with Kernel#then HOT 3
- can not use _url helper HOT 5
- Can't extract wrapped array through pattern-matching HOT 8
- Pattern matching in class method requires `include` instead of `extend`
- Traverse of a list with an unfrozen empty array returns a list with a frozen empty array HOT 2
- [Feature Request] Extract bind from Do notation HOT 4
- Implementing my own monad? HOT 1
- Do-notation with class methods HOT 3
- Map monoid HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dry-monads.