fast_immutable_collections icon indicating copy to clipboard operation
fast_immutable_collections copied to clipboard

Dart-FP integration

Open Solido opened this issue 4 years ago • 8 comments

Dart-FP => dfp

Open discussion for planning

For the first step can we consider a breaking change in FIC and plan a for 6.0 release ?

Is there some entites than we can remove from fic and depends directly on dfp ? Maybe evolve dfp entities for some new requirements too ?

@SandroMaglione

Solido avatar Jul 03 '21 00:07 Solido

As we discussed, we could implement some extension methods that add functional programming to FIC. The extension would not be included in FIC core but you would need to explicitly import it. Functional types will come from fpdart.

@marcglasberg what do you think about this idea? How do you propose we go about a possible integration and implementation?

SandroMaglione avatar Jul 03 '21 09:07 SandroMaglione

While working on the extension for List and Map on fpdart, I realised that these extension can be used also for IList and IMap as they are, without modifications. The only concern remained is performance. Nonetheless, fpdart using those extension already offers some quite handy methods to work with fp on dart collections.

@Solido @marcglasberg How would you suggest to move from here? Is there a way to involve FIC to improve performances?

SandroMaglione avatar Aug 03 '21 13:08 SandroMaglione

@SandroMaglione Hello, I am very sorry for the delay. I've been working 12 hours per day and haven't had much free time.

I don't have experience with fp, and don't know exactly what you are trying to achieve. When you say:

As we discussed, we could implement some extension methods that add functional programming to FIC. The extension would not be included in FIC core but you would need to explicitly import it.

Why exactly would FIC need to import extension methods? The users who are interested in fp can import both FIC and your lib, and they would have the extension methods working. I could also add to the docs a link to your lib explaining that they should import both if they want the fp features.

marcglasberg avatar Aug 05 '21 19:08 marcglasberg

The users who are interested in fp can import both FIC and your lib, and they would have the extension methods working.

Yes, that is what I realised while working on the extensions. You can use the methods from fpdart (bind, ap, head, etc.) also on IList since the extension is on Iterable. My last concern at this point is performance. I wonder if there could be a way to have better performances if the extension is directly on IList (not sure about that, maybe you can tell me about this).

I could also add to the docs a link to your lib explaining that they should import both if they want the fp features.

I would be willing to make a PR for this.

SandroMaglione avatar Aug 06 '21 06:08 SandroMaglione

No, if the extension is in the FIC package, or if it's in the IList itself, it won't make any performance difference. And it also won't make any usability difference, since the syntax the user needs to write to use it is the same.

marcglasberg avatar Aug 06 '21 20:08 marcglasberg

@SandroMaglione One detail: The IList and ISet are Iterables. However, the IMap is not an Iterable, and it's also not a Map.

marcglasberg avatar Aug 06 '21 20:08 marcglasberg

Okay. I believe then that by using the fpdart extensions it is now possible to use FIC and FP together by importing both packages separately.

However, the IMap is not an Iterable, and it's also not a Map.

This could be an issue. Do you have an idea on how this can be fixed? The only solution I can think of is to create a specific extension for IMap, which would break the separation between FP and FIC. Any other idea?

SandroMaglione avatar Aug 08 '21 06:08 SandroMaglione

I don't see a way for you to create an extension for the IMap without importing the IMap.

marcglasberg avatar Aug 08 '21 20:08 marcglasberg