News for hackers. Stuff that matters.
Re:Simplify Your Code: Functional Core, Imperative Shell by MarkMarine on Tuesday October 28, 2025 @10:42AM (#45733516)
These chains become easy to read and understand with a small language feature like the pipe operator (elixir) or threading macro (clojure) that takes the output of one line and injects it into the left or rightmost function parameter. For example: (Elixir) "go " |> String.duplicate(3) # "go go go " |> String.upcase() # "GO GO GO " |> String.replace_suffix(" ", "!") # "GO GO GO!"

(Clojure) ;; Nested function calls (map double (filter even? '(1 2 3 4)))

;; Using the thread-last macro (->> '(1 2 3 4) (filter even?) ; The list is passed as the last argument (map double)) ; The result of filter is passed as the last argument ;=> (4.0 8.0)

Things like this have been added to python via a library (Pipe) [1] and there is a proposal to add this to JavaScript [2]

1: https://pypi.org/project/pipe/ 2: https://github.com/tc39/proposal-pipeline-operator

Re:Simplify Your Code: Functional Core, Imperative Shell by netdevphoenix on Tuesday October 28, 2025 @12:56PM (#45735426)
If you get an exception, you might not know where it comes from unless you get a stack trace. Code looks nice but not practical imo
Re:Simplify Your Code: Functional Core, Imperative Shell by MarkMarine on Wednesday October 29, 2025 @10:26PM (#45755766)
I use Clojure all the time and I haven’t noticed the gripe you’ve got, but these are built in features of (somewhat) popular programming languages. Might not be for you but functional programming isn’t for everyone.