Git Product home page Git Product logo

Comments (7)

soutaro avatar soutaro commented on May 27, 2024 1

I think I got the point.

class Foo
  def each
    yield 1
    yield 2
  end

  include Enumerable
end

Foo.new.each         # => error!!

Okay, we need to revise the definition of the interface!

from rbs.

HoneyryderChuck avatar HoneyryderChuck commented on May 27, 2024 1

@soutaro just for clarity, I'm not arguing for a revision of the existing one, but to add a new one. The reasoning is, the current _Each already describes the requirement for implementing a class decorated with Enumerable. But an _EnumEach is common enough (IMO) to warrant defining it as a common interface (as most core and stdlib enumerables already do it).

from rbs.

soutaro avatar soutaro commented on May 27, 2024

Could you show me an example that requires no-block-given version?

from rbs.

HoneyryderChuck avatar HoneyryderChuck commented on May 27, 2024

Enumerable#each is the most obvious example, I think. For example:

:0> [].each
=> #<Enumerator: []:each>

Currently, the way it's defined, the rbs definition doens't match this case.

from rbs.

marcandre avatar marcandre commented on May 27, 2024

Enumerable#each is the most obvious example, I think. For example:

:0> [].each
=> #<Enumerator: []:each>

Currently, the way it's defined, the rbs definition doens't match this case.

This is the definition you are looking for.

It's basically correct, except the second should return ::Enumerator[Elem, self], so I opened a PR to fix that.

from rbs.

HoneyryderChuck avatar HoneyryderChuck commented on May 27, 2024

I was actually arguing for this definition to be part of a common interface, instead of being rewritten in every project implementing each with no block, which I think it's common enough, wouldn't you agree?

from rbs.

marcandre avatar marcandre commented on May 27, 2024

It could definitely be useful as a shorthand, but maybe should be named something different like _Iterable?

I think _MethodName should be restricted to interfaces that implement that method_name minimally. So @soutaro's point was that if you want to accept that an object that implements each (which is what the name _Each suggests), then you probably don't want to impose that each without a block work, only that each with a block does.
If you want to specify that your class implements each "correctly", then yes, you should have these two interfaces and a shorthand might be useful. I'm not sure how often this is, and how often that method is necessarily named each...

from rbs.

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.