Comments (2)
This already works because Literal types are just objects that respond to ===
, and that's the same interface that Ruby uses for case
/when
and case
/in
. 🎉
The only limiting factor is it will not work with types defined inline, e.g.
case input
in _Union(:sm, :md, :lg)
# ...
end
This is because Ruby pattern-matching allows for either ()
or []
to be used, so what it tries to do is call deconstruct
on _Union
so it can match the part in parentheses. The only way around this is to name your generics, like your example above.
from literal.
This already works because Literal types are just objects that respond to ===
, and that's the same interface that Ruby uses for case
/when
and case
/in
. 🎉
The only limiting factor is it will not work with types defined inline, e.g.
case input
in _Union(:sm, :md, :lg)
# ...
end
This is because Ruby pattern-matching allows for either ()
or []
to be used, so what it tries to do is call deconstruct
on _Union
so it can match the part in parentheses. The only way around this is to name your generics, like your example above.
from literal.
Related Issues (20)
- Add generic Range type
- `Literal::Some` and `Literal::Nothing` should implement `#value_or_raise!` and deprecate `value` HOT 1
- Comparison operators for `Literal::Maybe` and `Literal::Result` objects HOT 1
- `Literal::Struct` and `Literal::Data` should implement the `[]` and `[]=` hash-like interface
- `Literal::Some#filter` is actually passing `self` to the block HOT 1
- Rails support
- Implement `#as_pack` and `.from_pack` on `Literal::Data` and `Literal::Struct` HOT 1
- Inherited object and kwargs HOT 1
- A "module defined hook" mixin
- undefined method `after_defined'
- Starting over HOT 3
- Switch to `prop` instead of `attribute` HOT 4
- `attribute` `default` option doesn't work with `:&` HOT 2
- Update gem spec to exclude test files
- Bring back the option to disable type checking
- Bring back object marshalling for literal data structures
- Add `predicate` options to literal properties HOT 3
- Some of the type `inspect` methods are broken
- How to forward arguments to parent class? HOT 2
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 literal.