Coder Social home page Coder Social logo

Comments (9)

flash-gordon avatar flash-gordon commented on August 28, 2024 1

@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.

lcolombini avatar lcolombini commented on August 28, 2024 1

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.

flash-gordon avatar flash-gordon commented on August 28, 2024

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.

slavadev avatar slavadev commented on August 28, 2024

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.

jdwolk avatar jdwolk commented on August 28, 2024

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.

flash-gordon avatar flash-gordon commented on August 28, 2024

@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.

lcolombini avatar lcolombini commented on August 28, 2024

@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.

EduardoSimon avatar EduardoSimon commented on August 28, 2024

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.

kleinjm avatar kleinjm commented on August 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.