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

Is is possible to map from Option[T] to Option[S]? #4

Open
MyRaiser opened this issue Mar 3, 2023 · 1 comment
Open

Is is possible to map from Option[T] to Option[S]? #4

MyRaiser opened this issue Mar 3, 2023 · 1 comment

Comments

@MyRaiser
Copy link

MyRaiser commented Mar 3, 2023

For example if we have:

  • a variable t of type Option[T]
  • a function fn of type func(T) S

And t.Map(fn) should be of type Option[S] . The Map() does something like this:

if t.IsSome() {
    return Some[S](fn(t))
}
return None[S]()

Is is possible?

@Yakiyo
Copy link

Yakiyo commented Aug 11, 2023

this should have been possible. the actual map method in rust (ref) does it. but gust doesnt (ref)
Map should accept a func that takes a param T and returns S
a workaround could be

if t.IsSome() {
  return Some[S](fn(t.Unwrap()))
}
return None[S]()

Doing fn(t) means ur taking an Option as a param, not the inner value.

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