@trtt Apart from using solutions for pattern matching such as gara, you can 
iterate recursively over HLists and use if/case statements

This is how I would write a barebone HList, but for some reason the recursive 
printAll does not seem to work
    
    
    type
      HListKind = enum hkNil, hkCons
      HList*[H, T] = ref object
        case kind*: HListKind
        of hkNil:
          discard
        of hkCons:
          head*: H
          tail*: T
    
    let hNil*: HList[void, void] = HList[void, void](kind: hkNil)
    proc cons*[H; T](hd: H, tl:T): HList[H, T] =
        HList[H, T](kind: hkCons, head: hd, tail: tl)
    
    let l = cons("hi", cons(2, hNil))
    
    # proc printAll[H; T](hl: HList[H, T]) =
    #     case hl.kind
    #     of hkNil:
    #         discard
    #     of hkCons:
    #         echo hl.head
    #         printAll(hl.tail)
    
    # printAll(l)
    
    
    Run

Reply via email to