dogweather
My best Elixir in Python
After using Elixir for a long time I can’t wrap my mind around Python’s APIs.
So with the help of functoolz curry, flip, and pipe, I can write HTML parsing code like this:
def parse_title(dom: XmlResponse) -> Title:
name = pipe(
dom
, html.xpath("//TITLE-TEXT")
, text.titleize
)
number = pipe(
dom
, html.xpath("//TITLE-NUM")
, text.split(" ")
, seq.get(1)
)
children = _parse_divisions_or_articles(number, dom)
url = _source_url(number)
return Title(name, number, children, url)
I’m not re-writing any of these functions. I’m just wrapping each of them with a little code to give them a consistent interface. And once they each have this new API, they can be easily chained together.
Anyone else adapting other languages to the Elixir fluent API style? I don’t get much love from the Python community when showing this kind of code. ![]()
Most Liked
kokolegorille
I think You would get the same kind of love from the Elixir community when showing Object Oriented Elixir code ![]()
dimitarvp
This should be qualified with context: many people said that learning an immutable FP language made them write more understandable, clearer, easier to read, easier to debug and test code in imperative OOP languages.
It’s not about trying to make Python stand on its head. It’s about writing Python that is… less ugly and hard-to-work-with Python.
Languages should indeed cross-pollinate as @ivanov said.
One prominent example: after Rust made enums (sum types) prevalent in compiled languages – nevermind that OCaml and Haskell had them for ages before that but oh well
– then many people started wanting them in other languages.
ivanov
I got to attend the annual American Geophysical Union (AGU) fall meeting that was in San Francisco a few weeks ago, thanks to a pass from Matt Rocklin (author of functoolz and also dask). Someone there was also sharing similar positive sentiments about this kind of chaining, and said how it felt functional and Lisp-like, to which Matt responded something like “that’s exactly why I built it, I was re-writing in Python pieces that were missing for me that I was used to having in Clojure”.
I’d call it cross-pollination ![]()
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









