Comments (7)
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.
@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.
Could you show me an example that requires no-block-given version?
from rbs.
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.
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.
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.
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)
- A sound and complete type for Enumerable#inject HOT 1
- Feature proposal: `rbs diff` command HOT 1
- Feature proposal: `rbs todo` command
- Should gems include private methods and constants in their RBS files? HOT 1
- Allow Type Variable constraints to be arbitrary types HOT 1
- `Enumerable#to_set` accepts a block
- `SimpleDelegator` is missing HOT 1
- Many Kernel methods are defined as Object methods HOT 6
- URI is missing HOT 3
- Logger is missing
- Set#intersect?, Set#disjoint? signatures are too narrow HOT 1
- The `range[T]` type definition is to restrictive
- `_Range[T]` shouldn't return `T?` for `begin` and `end`
- override a function with a block fails
- Singleton does not have method `instance` HOT 1
- add an `assert_const_type`
- Cannot specify type variables for `instance` HOT 6
- manifest.yaml does not allow gems as dependencies
- Proposal: making `Class` and `Module` classes generic -- `Class[I]` and `Module[I]` HOT 9
- Feature proposal: Multiple error on `rbs validate` 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 rbs.