[HN Gopher] I made a tiny library for switches and sum types in Lua
       ___________________________________________________________________
        
       I made a tiny library for switches and sum types in Lua
        
       Author : alurm
       Score  : 75 points
       Date   : 2024-12-30 07:08 UTC (2 days ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | furyofantares wrote:
       | Cool.
       | 
       | I admit it takes a minute to grok, and the example of a_square
       | being a rectangle but not a square added some unnecessary
       | confusion.
        
         | alurm wrote:
         | Thanks, fixed.
        
       | SSchick wrote:
       | Sorry but this is 12 lines of Lua code, what is the value
       | proposition/use case here? I'm legitimately curious.
        
         | alurm wrote:
         | Honestly, not much.
         | 
         | I found it nice how it's possible to emulate switches in Lua
         | with so little code, without the result looking too ugly. You
         | may find this pattern useful. That's it.
         | 
         | The catch is that, unlike with normal switches or with a series
         | of "if"s, there's a whole bunch of indirection added via
         | functions, so it's not very efficient.
         | 
         | Perhaps LuaJIT can inline these functions, but I haven't tested
         | it.
        
       | tetris11 wrote:
       | Pretty neat - I might incorporate this into my awesomeWM, which
       | has a lot of if/else provisioning for some custom window
       | functions I wrote
        
       ___________________________________________________________________
       (page generated 2025-01-01 23:01 UTC)