Comments (6)
These reified types could also brings way to call constructors, and even in a "data-driven" way (spreading vector/map).
from clojuredart.
Types are rarely used in Dart APIs so we could consider changing the evaluation of a class name from a Type
instance to something ClojureDart specific.
This would have the benefit that instance?
could work (adieu dart/is?
).
At first I thought that this value should be a function too so as to be used to create instances -- even taking maps as arguments! However with named constructors it's not so clear and I'm not sure bundling all constructors together is a good idea.
Maybe the more generic idea of doing "clojurization" for tear-offs. Syntactically we could leverage var
: #'m/ListView.separated
would evaluate to a Clojure fn taking named parameters as maps.
from clojuredart.
into-array
accepts a type parameter that we can't observe, it's just there for compatibility with Clojure.
with reified literal classes we could imagine making it work but it would require adding a "makeFxiedList" method to class literals.
Then it begs the question: why to stop at Lists, what if I want sets or any other kind of typed collections?
Map is a good example because now you need two types, so it means it can't be just a function of a single type literal.
Special-casing for lists and only lists may be ok after all...
from clojuredart.
Another use-case: object to map conversion (bean
-like)
https://clojurians.slack.com/archives/C03A6GE8D32/p1697712372844039
from clojuredart.
class Class<T> {
final Set<Type> ancestors;
bool isInstance(dynamic x) => x is T;
bool descendsFrom(Class klass) => ancestors.contains(klass.type);
Type get type => T;
const Class([this.ancestors = const {}]);
@override
operator == (dynamic other) => (other is Class) && (other.type == type);
@override
get hashCode => T.hashCode ^ 19870801;
}
main() {
final x = <dynamic>[];
final y = <String>[];
print(x.runtimeType);
print(y.runtimeType);
print(x.runtimeType == y.runtimeType);
const list = Class<List>();
const strings = Class<List<String>>();
print(list.isInstance(2));
print(list.isInstance(x));
print(list.isInstance(y));
print(strings.isInstance(x));
print(strings.isInstance(y));
const string = Class<String>({Object});
const object = Class<Object>();
print(string.descendsFrom(object));
}
from clojuredart.
A Flutter class using Type
objects https://api.flutter.dev/flutter/widgets/Actions/Actions.html
from clojuredart.
Related Issues (20)
- Add warning on impossible nil checks
- Transitive dart dependencies HOT 6
- LD -XLinker is invalid option compiling for native app HOT 8
- multiple bindings in :bg-watcher
- Support multiple bindings in `:bg-watcher`
- platform conditionals HOT 3
- doseq and for but for streams
- Add a "nano pass" to the compiler to perform statements lifting
- Stop generating dart functions HOT 1
- Make magicast open
- `:keep-alive` on `f/widget` HOT 1
- Can't `with-open` HOT 2
- Printing cyclic data structure causes stack overlow HOT 1
- `doseq` with `await` in body evaluates to a future HOT 1
- cljd type parameter inference on static methods could be better
- Error: Can't use an expression of type 'void Function()?' as a function because it's potentially null.
- static methods on interfaces backing protocols
- Type hinting a `Future` fn won't compile
- Resolution of types across conditional import/export
- Loose type inference on functions that are type hinted
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 clojuredart.