Skip to content
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

create Maybe from value #4

Open
demetere opened this issue May 30, 2024 · 2 comments
Open

create Maybe from value #4

demetere opened this issue May 30, 2024 · 2 comments

Comments

@demetere
Copy link

Hello,

I would like to know if there is a way to create Some or Nothing based on a value. Specifically, if the value is None, it should create Nothing, and if the value is present, it should be encapsulated within Some.

I saw a great example of this in one of the libraries that was put as an alternative to your repositories. This implementation is the one I am referring.

If this functionality does not currently exist, I am willing to implement it if we can agree on the approach.

@francium
Copy link
Member

francium commented Jun 1, 2024

Hi,

I think a Maybe.from makes sense. But we don't have a Maybe namespace (class) unless the user does import maybe + maybe.from. So maybe we'll want to just do a function most likely such as to_maybe? We could call it from, but the issue then become of 'from' being a very generic name and unless the user does a fully qualified call, maybe.from, it becomes somewhat confusing if from is imported, eg from maybe import from + from(...). I hope that makes sense.

Second question is, that library, dry-python has two versions, from_value and from_optional, I'm not sure if we need both, I don't quite understand the rationale for having two. From what I'm thinking, a single function that handles the from_optional semantics (None | T -> Maybe[T]) should be sufficient.

Perhaps we could clarify these questions first, and then you're welcome to take this on.

@demetere
Copy link
Author

demetere commented Jun 1, 2024

I completely agree with you. We can create a function called maybe or, as you mentioned, to_maybe. I've already created a maybe function, but renaming it is a minor issue.

I also find the dry-python decision to have two functions a bit confusing. Perhaps they intended to encapsulate None inside Some, but I don't see many real-world cases for that. In this context, from_optional seems more applicable, and we can consider going this route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants