Fun(c) 2018.7: John De Goes - FP to the Max
Why Stack Overflow recommends it
Stack Overflow users link it when explaining how to model side effects with typeclasses like Console[F[_]] and how to make effectful programs testable in Scala.
Recommended by 4 people across 4 different months, 2019 to 2019.
What it is
A live-coding talk by John De Goes at the Fun(c) meetup, hosted by Expedia Group. He takes a small procedural Scala program full of partial functions and side effects and incrementally refactors it into a purely functional one using the tagless-final pattern, showing both the benefits and the costs of pure FP.
What people said
Recommends amitayh · 2019-01 · Stack Overflow · on “Typeclass dependency with tagless-final”
After watching John De Goes' "FP to the Max" ( [this video] ) I'm wondering about approaches for writing FP programs in the tagless-final pattern. Say I have some typeclass for modelling a side-effecty thing (taking his Console example): trait Console[F[_]] { def putStrLn(str: String): F[Unit] def getStrLn: F[String] } How would you depend on Console ? Implicitly Like demonstrated in his video: def inputLength[F[_]: Functor: Console]: F[Int] = Console[F].getStrLn.map(_.length) Pros : The function signature is clean, and you can benefit from typeclass automatic derivation Explicitly By passing the instance to the function directly: def inputLength[F[_]: Functor](console: Console[F]): F[Int] = cons
Recommends Vasily802 · 2019-03 · Stack Overflow · on “Cannot run a scala script (fpmax by jdegoes)”
Here's a brilliant web talk by J. A. De Goes: [this video] - highly recommended for everyone interested in functional programming And here's accompanying code gist: [LINK] When I run $ scalac fpmax.scala , it compiles everything to a new directory fpmax But then when I run scala App0 , it gives me error: Exception in thread "main" java.lang.NoClassDefFoundError: App0 (wrong name: fpmax/App0) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:7
Recommends Krzysztof Atłasik · 2019-07 · Stack Overflow · on “How to implement db operation in scala functional programming”
If you want to create a purely functional app, you can't do any side effects, but without side effect how can we do anything useful (write text to console, read data from the database, etc.)? Basically, what we can do is "cheating" by wrapping all code that is not pure (is performing any side effects) in effect [LINK] which is usually called IO monad. Impure actions wrapped with IO are not executed until explicitly started (usually by calling method named like unsafeRun ). And since that wrapped actions are just values, you can return them from functions, assign to variables and do everything you would do with plain values: import cats.effect.IO //you'd have to add cats-effect dependency to
Recommends Matthew DiLoreto · 2019-08 · Stack Overflow · on “how to paste multiple line to a command line prompt of a scala stdIn process?”
This is a question I'm sure almost all programming students encounter at some point. The essence of your question seems to be "How can I simulate side-effects (input/output in this example) in my program?" You can imagine the same issue if your code called database.insert(...) instead of scala.io.StdIn.readLine or println(...) . It's all the same problem really. In a test environment, how can you feed input to a program like this? I would recommend looking at this excellent example [LINK] (explained in this video by John De Goes [this video] ) of your exact problem, addressed in a functional style. The final outcome of the program may be overkill for your app, and one of the intermediate programs