Giter Club home page Giter Club logo

Comments (6)

lrhn avatar lrhn commented on June 30, 2024 1

This is where we disagree.

A function of type bool Function(String) may be used as a predicate, or a filter, a condition, or a selector. That's different roles, depending on which values it will be called on and how often. Even if the words mean approximately the same thing, and may be the same function in all the cases, there is intent in the naming.

I'd want to put that name into the variable, not the type.
If I have a bool Function(String), I get to choose how to use it, and I can use it anywhere that type is allowed.
If it was typed as Predicate<String> I wouldn't know as easily whether I could use it as a Filter<String>.

Having type names for each role a function type can occur in, that just doesn't scale. There are too many, and they don't actually enforce anything.
An int Function(String, String) may be a Comparator<String>, or it may be a ReverseComparator<String>, but as type aliases, they're the same type.

And using named types, IMO, hurts readability rather than help it, by hiding the actual function type.

Roles should be variable names.

from sdk.

lrhn avatar lrhn commented on June 30, 2024

Java does things this way because they don't have first class functions.
Dart does, and can just declare typedef Consumer<T> = void Function(T);, with no class or interface needed.

I don't see any need for the platform libraries to expose such interfaces (or named function types for that matter), when a literal function type is fine. Maybe that's just my personal preference, I find it easier to read void Function(T) than Consumer<T> because I can see what it means, without having to learn a number of names.

from sdk.

Ing-Brayan-Martinez avatar Ing-Brayan-Martinez commented on June 30, 2024

To talk about functional programming, we must always keep in mind the type signature of the functions. This concept is important if we had to write a function in an exotic language like Haskell, we would do it this way.

add_two :: Integer -> Integer
add_two = a + 2

As you can see the type signature is very important. The idea of ​​this library is to have a collection of higher order functions using typedef of all possible type signatures or the vast majority standardized with key names that allow abstracting concepts that facilitate the implementation of algorithms, this facilitates communication between programmers.

For example, if I ask someone if it is better to implement a Consumer or a Predicate in my algorithm, the other members will be able to understand what I am talking about, this helps teams that use agile ways of working.

It also allows us to standardize, avoid repeated code, and helps reduce the code base to maintain because we can always reuse the same functions that the base SDK already provides.

We can have most signature types registered in one place to avoid getting lost in so much code.

from sdk.

Ing-Brayan-Martinez avatar Ing-Brayan-Martinez commented on June 30, 2024

Well you decide, this api is quite simple, for that matter it could be written like this:

typedef Predicate<T> = bool Function(T value)

This satisfies all Predicate of any type possible thanks to the generic type T

typedef Predicate<String> = bool Function(String value);

typedef Predicate<int> = bool Function(int value);

This is where duplicates begin, which I want to avoid by using a generic type.

from sdk.

dart-github-bot avatar dart-github-bot commented on June 30, 2024

Labels: area-language, type-enhancement
Summary: The user proposes creating a dart:function API to standardize common higher-order function declarations, inspired by Java's java.util.function package. They suggest two implementation approaches: using functional interfaces or typedefs.

from sdk.

mraleph avatar mraleph commented on June 30, 2024

We have no plans to do this.

from sdk.

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.