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

Ex 5 Level 6 flatmap #319

Open
brookie13 opened this issue Nov 27, 2022 · 7 comments
Open

Ex 5 Level 6 flatmap #319

brookie13 opened this issue Nov 27, 2022 · 7 comments

Comments

@brookie13
Copy link

Hi currently stuck with level 6 for exercise 5. I am not too sure on how I can return a Maybe without having to typecast it. I've thought about using the map() function in the class and then take the Maybe value inside but I realised that the value would be considered as R instead of Maybe (thus leading to typecasting which brings up the warning). What is another way to go about with this problem?

@bransometan
Copy link

I managed to solve it with this approach by first assigning mapper.apply(this.thing) to the output of the Function which is Maybe<? extends R> and call it (e.g temp). Then, I just return Maybe.<R>of(temp.thing).

@glendon29
Copy link

glendon29 commented Nov 28, 2022

what i did was to do mapper.apply(this.thing).orElse(null) since the orElse method u created points to this which in this case refers to the mapper.apply

@brookie13
Copy link
Author

I attempted this method but I got the error CAP#1 cannot be converted to Maybe<? extends R>. What did you do to avoid this?

@glendon29
Copy link

@brookie13 do u mind if u share ur method

@brookie13
Copy link
Author

hm
@glendon29

@glendon29
Copy link

glendon29 commented Nov 28, 2022

oo ur parameter is wrong. if u see the test case u realise flatMap can take in a param of Maybe

Therefore ur flatMap param must be
Function<? super T, ? extends Maybe<? extends R>>

@brookie13

@brookie13
Copy link
Author

OHHH okay I fixed it and now it works. Thank you so much

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

3 participants