News for hackers. Stuff that matters.
Re:Elixir for Humans Who Know Python by dr_kiszonka on Thursday June 27, 2024 @10:51AM (#40811146)
I really miss pipes in Python. Maybe in version 4.x?
Re:Elixir for Humans Who Know Python by ralmidani on Thursday June 27, 2024 @04:42PM (#40814860)
If it doesn’t break backward-compatibility there wouldn’t be a need to release a new major version (which very few people have the stomach for anyway).
Re:Elixir for Humans Who Know Python by Svetlitski on Thursday June 27, 2024 @09:07PM (#40816860)
You can implement pipes via operator overloading in Python. Whether or not you should is a different question:

  class Pipe:
      __slots__ = ("value",)
  
      def __init__(self):
          self.value = None
  
      def __or__(self, x):
          return x(self.value)
  
      def __ror__(self, x):
          self.value = x
          return self
  
  v = Pipe()
  
  def double(x):
      return x + x
  
  def triple(x):
      return x + x + x
  
  pipeline_result = 3 + 7 |v| double |v| triple |v| double
  normal_result = double(triple(double(3+7)))
  assert pipeline_result == normal_result