Code Monkey home page Code Monkey logo

Comments (6)

cgrand avatar cgrand commented on May 13, 2024

These reified types could also brings way to call constructors, and even in a "data-driven" way (spreading vector/map).

from clojuredart.

cgrand avatar cgrand commented on May 13, 2024

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.

cgrand avatar cgrand commented on May 13, 2024

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.

cgrand avatar cgrand commented on May 13, 2024

Another use-case: object to map conversion (bean-like)
https://clojurians.slack.com/archives/C03A6GE8D32/p1697712372844039

from clojuredart.

cgrand avatar cgrand commented on May 13, 2024

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.

cgrand avatar cgrand commented on May 13, 2024

A Flutter class using Type objects https://api.flutter.dev/flutter/widgets/Actions/Actions.html

from clojuredart.

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.