Skip to content

add Scala functor example #10

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

Merged
merged 3 commits into from
Dec 10, 2018
Merged

add Scala functor example #10

merged 3 commits into from
Dec 10, 2018

Conversation

0lejk4
Copy link
Contributor

@0lejk4 0lejk4 commented Dec 8, 2018

Provided Functor example for a Scala language. Functor is implemented using typeclass in Scala and usually is provided by some library like Cats or Scalaz where it is much more complicated than in this simple example.

@0lejk4 0lejk4 closed this Dec 8, 2018
@0lejk4
Copy link
Contributor Author

0lejk4 commented Dec 8, 2018

Sorry, didn't see that someone already provided with Scala examples. Should check Pull Requests first next time) But just in case i`ll reopen it.

@0lejk4 0lejk4 reopened this Dec 8, 2018
@tshemsedinov
Copy link
Member

@DzyubSpirit can you please review this?

@DzyubSpirit
Copy link
Contributor

Yeah, sure :)

@DzyubSpirit
Copy link
Contributor

This PR tries different from #9. I would say #9 approach is more like Javascript and this PR is more like Haskell in terms of functor definition. #9 and Javascript just implement map method in every functor type (Maybe, Either, Array...). This PR and Haskell typeclasses additionally create Functor entity which is an abstraction of more concrete types (Maybe, Either, Array...)
That makes this PR approach more difficult but at the same time more type safe.
I think both of the #9 should be landed as it is and this code should go into advanced folder

import Maybe._
import FunctorSyntax._

print(just("2").fmap(_.toDouble).fmap(a => a + 3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(just("2").fmap(_.toDouble).fmap(a => a + 3))
println(just("2").fmap(_.toDouble).fmap(a => a + 3))

@0lejk4
Copy link
Contributor Author

0lejk4 commented Dec 10, 2018

Just added README, refactored names, moved to Scala/Advanced folder and added comments about the second example, please check it once more. @DzyubSpirit

@DzyubSpirit DzyubSpirit merged commit 40e4917 into HowProgrammingWorks:master Dec 10, 2018
@DzyubSpirit
Copy link
Contributor

Good work!

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

Successfully merging this pull request may close these issues.

3 participants