-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider removing Option from package exports #79
Comments
Hi! 👋 Unfortunately, that was an explicit design decision since I didn't want to add a dependency on an external package (that could introduce breaking changes whenever they wish), and the workaround for that is just hand-rolling an That being said, I am familiar with fpdart and did consider using their Now, here's what a workaround would look like (that I probably should document in the FAQs...): // NOTE: This is untested; you may need to tweak this
// rearch_fix.dart
import 'package:rearch/rearch.dart' as rearch;
import 'package:fpdart/fpdart.dart' as fpdart;
export 'package:rearch/rearch.dart' hide Option;
extension IntoFpdartOption on rearch.Option {
// you can name this whatever you want
fpdart.Option<T> into<T>() {
return switch (this) {
// TODO: make the fpdart.Option here
rearch.Some(:final value) => throw UnimplementedError(),
rearch.None() => throw UnimplementedError(),
};
}
} Then import |
Thank you for the workaround. I agree on not depending on Given that you've put a lot though into this project, I imagine that you've considered simply using nullable types instead on an Option type? T unwrapOr(T defaultValue) {
return switch (this) {
null => defaultValue,
(final T value) => value,
};
}
T unwrapOrElse(T Function() defaultFn) {
return switch (this) {
null => defaultFn(),
(final T value) => value,
};
}
R? map<R>(R Function(T) mapper) {
return switch (this) {
null => null,
(final T value) => mapper(value),
};
} I see that you like the Rust approach of Option types which I agree with. However, there is also something to be said for keeping with the features of the programming language. With that said, thank you for your work on this package. |
Yup, and I really wish it was a nullable type. The issue is if someone has an AsyncValue with a nullable type, e.g., The
Absolutely! I personally haven't (yet, at least) used fpdart or any similar libraries for this exact reason. Maybe fpdart doesn't break conventions too much 1, but many similar types of packages, across programming languages, fight too much with their languages' conventions. Footnotes
|
Thank you for your reflections. I see the value of your arguments and would do the same in an internal library. For an external library like Another alternative is to use a more specific name for the Option class, possibly more closely related to its actual use. I know this breaks with Rust conventions but it would resolve the issue. At any rate, thanks for the discussion! |
@Mattertorian You can always use a custom Typedef |
I was not aware of that. Can you give a quick demonstration of how it is done? |
rearch_safe.dart: import 'package:rearch/rearch.dart';
export 'package:rearch/rearch.dart' hide Option;
typedef ROption = Option; test.dart: import 'rearch_safe.dart';
import 'package:fpdart/fpdart.dart';
void test(Option valueFpDart, ROption valueRearch) {} |
Thanks for the snippet. I can see that working if put into a separate package that is then depended upon as a proxy for |
You can use it directly in your project. Just import |
True. But it seems less ergonomic when using the Quick Fix (which would provide both |
Yeah, it will offer you all available options: relative paths, absolute paths, package path, ... I use prefixes for my libs in order to avoid name clashes: fllib, flib, llib, lib, pglib, ... so I do a lot of copy paste. I don't think it's worth it to create a proxy package, but it's up to you :) |
Thanks for a great package!
My issue is pretty much the title: the Option class exported by this package conflicts with the Option class from dedicated FP packages like fpdart. Having to hide Option on every import is quite combersome. I understand the internal usage. It would be great if it did not leak.
Keep up the good work!
The text was updated successfully, but these errors were encountered: