#56 Golang - Exploring Generators - The Power of Iterators

Поделиться
HTML-код
  • Опубликовано: 7 янв 2025

Комментарии • 6

  • @ragnadrok7
    @ragnadrok7 3 месяца назад

    Hi Could you do something for observability
    Like sending metrics to Prometheus for count and latency, maybe a generic way to set it up

    • @codeheim
      @codeheim  2 месяца назад

      Sure, will do!

  • @RiccardoPasquini
    @RiccardoPasquini 3 месяца назад +3

    Is this added to go 1.23?

    • @codeheim
      @codeheim  3 месяца назад +1

      Thank you! I did not know that. I have been using this kind of generator for a long time now. Should switch to this.

  • @MarcelloH
    @MarcelloH 3 месяца назад

    The version where yield in Go does work:
    mySeq := func(yield func(n int) bool) {
    num := 0 // Initial value to find the first prime
    for {
    num = nextPrime(num)
    if isPrime(num) {
    yield(num)
    }
    }
    }
    i = 0
    for v := range mySeq {
    i++
    fmt.Println("Prime #", i, ": ", v)
    if i == 10 {
    break
    }
    }

    • @codeheim
      @codeheim  2 месяца назад

      Thank you! I made a video on this: ruclips.net/video/S4H4q7aEMuU/видео.html