flutterdartoopfunctional-programmingdartz

is dartz Either Nesisty or just matter of taste?


So before I start I,m a beginner in Flutter and in programming all together.

I used to just follow video tutorials and consider their best practices, one of my earliest tutorials introduced me to the Dartz library and it was used when getting data from an API.

final Either<ServerException, answer> result = await repository.get(...);
result.fold(
 (exception) => handle, 
 (answer) => yaay
);

it was introduced as the only way so I thought that, however now I know more about the future type and all its features, I also learned that I can handle exceptions with OnError or try and catch.

more search lead me to that Dartz really offers the style of Functional programming to Dart because of its OOP language.

given all of that

1- is it better or just some people prefer it that way?

2- why I felt that people hate OOP that much?

3- is it any good at all for someone still learning like me to use a library to change language style and avoid using native code behavior?


Solution

  • I prefer fpdart, and am using it in production for a number of clients.

    https://pub.dev/packages/fpdart has this to say about dartz:

    Comparison with dartz One of the major pain points of dartz has always been is lack of documentation. This is a huge issue for people new to functional programming to attempt using the package.

    dartz was released in 2016, initially targeting Dart 1.

    dartz is also missing some features and types (Reader, TaskEither, and others).

    Fpdart is a rewrite based on fp-ts and cats. The main differences are:

    Fpdart is fully documented. Fpdart implements higher-kinded types using defunctionalization. Fpdart is based on Dart 3. Fpdart is completely null-safe from the beginning. Fpdart has a richer API. Fpdart implements some missing types in dartz. ? Fpdart (currently) does not provide implementation for immutable collections (ISet, IMap, IHashMap, AVLTree).