SandroMaglione / fpdart

Functional programming in Dart and Flutter. All the main functional programming types and patterns fully documented, tested, and with examples.
https://pub.dev/packages/fpdart
MIT License
543 stars 45 forks source link

Misleading documentation #35

Closed KristianBalaj closed 2 years ago

KristianBalaj commented 2 years ago

There is a comparison to dartz package that states that the fpdart is richer.

However, fpdart does not provide the core typeclasses like monoid, functor, applicative or monoid 🤔

On the other hand, I'm not sure if all this typeclasses can be effectively used in OO language like dart. Also, I was not able to use these typeclasses from dartz either. I wanted to use monoid on my data class, however it was already extending equatable so it was not possible to be used since the dartz package made the monoid a class that needs to extended.

I think that these typeclasses could be implemented in dart using double dispatch to overcome such problem.

SandroMaglione commented 2 years ago

Hi @KristianBalaj

fpdart has a typeclass folder that contains all the typesclasses that form the core of the package. In fact, every major type (Option, Either, Task, etc.) extends from this typeclasses.

fpdart provides also a Monoid typeclass. You can use it like this:

class CustomMonoid extends Monoid<int> {
  @override
  int combine(int x, int y) {
    // TODO: implement combine
    throw UnimplementedError();
  }

  @override
  // TODO: implement empty
  int get empty => throw UnimplementedError();
}

or using instance:

final instance = Monoid.instance<String>('', (a1, a2) => '$a1$a2');

If instead you cannot use extends because you are already extending Equatable, in some cases you can use with:

class CustomMonoid extends Equatable with Monoid<int>

Let me know if you have a more specific use case and if I can help