r/functionalprogramming • u/hunterh0 • Mar 16 '23
Question [beginner question] Functional programming for data engineering, where to start?
The hugging face dataset API mainly handle data manipulation with a map function. However, it looks like they are hacking python to achieve this and it is lacking other functional features. Also it feels clumsy when you need to compose multiple mapping that produce different datatypes. Non the less, it’s a great tool, but it looks like an FP focused language can do better.
I have no experience in FP languages, but it seems that using ”functional programming” to manipulate data makes your code cleaner and shorter. Which language/framework do you recommend that can replace python in at least the data preperation/pipline part? Or maybe adapting python to a more FP style?
10
u/Slow_Building_210 Mar 16 '23
Your best bet (for now) is probably using Scala in the Databricks environment. Link to the free Databricks Community Edition:
https://community.cloud.databricks.com/login.html
5
u/taksuii Mar 16 '23
Scala! This book may help you, Functional Programming in Scala https://g.co/kgs/sGU7cB
5
u/WallyMetropolis Mar 16 '23
Pure functional programming in Python is not super well supported. But nothing is stopping you from using MyPy and pre-commit to ensure your type hints all line up properly and writing your code as a sequence of pure functions. This style of coding can really help with things like the reasonability of your code and ease of testing, even if you aren't getting into state monads or "pure, functional" I/O.
8
u/OpsikionThemed Mar 16 '23 edited Mar 16 '23
That is, in fact, one of the great strengths of the functional approach - you can create a bunch of small, obviously correct functions that do a simple thing, and then compose them to produce your complicated result. Like, as a small example, a capitalizer:
All the functions there (except for maybe mapHd/tl) are standard, and chaining them together like that is pretty easy to read once you're used to it. And more to the point, all of them are used all over, in composition chains just like this. It's a very powerful (and not at all clumsy) idiom.
6
u/[deleted] Mar 16 '23
Look at the following. Haskell Idris OCaml These languages have type systems. If you prefer dynamic languages Look at Elixir or Clojure. I wish I could work in an FP all day. Sadly I am stuck in a mostly imperative world.
3
u/Traditional_Hat861 Mar 17 '23
RockTheJVM is a good resource