example

package
v0.0.0-...-576931e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Code generated by github.com/goghcrow/go-co DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fibonacci

func Fibonacci() ʂɘʠ.Iterator[int]
func Fibonacci() Iter[int] {
	a, b := 1, 1
	for {
		Yield(b)
		a, b = b, a+b
	}
}

func Grep

func Grep(s string, lines []string) (_ ʂɘʠ.Iterator[string])
func Grep(s string, lines []string) (_ Iter[string]) {
	for _, line := range lines {
		if strings.Contains(line, s) {
			Yield(line)
		}
	}
	return
}

func PowersOfTwo

func PowersOfTwo(exponent int) (_ ʂɘʠ.Iterator[int])
func PowersOfTwo(exponent int) (_ Iter[int]) {
	for r, i := 1, 0; i < exponent; i++ {
		Yield(r)
		r *= 2
	}
	return
}

func Range

func Range(start, end, step int) (_ ʂɘʠ.Iterator[int])
func Range(start, end, step int) (_ Iter[int]) {
	for i := start; i < end; i += step {
		Yield(i)
	}
	return
}

func ReadFile

func ReadFile(name string) (_ ʂɘʠ.Iterator[Line])
func ReadFile(name string) (_ Iter[Line]) {
	file, err := os.Open(name)

	if err != nil {
		Yield(Line{Err: err})
		return
	}

	r := bufio.NewReader(file)
	for {
		line, prefix, err := r.ReadLine()
		if err == io.EOF {
			break
		} else if err != nil {
			Yield(Line{Err: err})
		} else {
			Yield(Line{Bytes: line, Prefix: prefix, Err: err})
		}
	}
	return
}

func Run

func Run()

func SampleGetEvenNumbers

func SampleGetEvenNumbers(start, end int) (_ ʂɘʠ.Iterator[int])
func SampleGetEvenNumbers(start, end int) (_ Iter[int]) {
	for i := start; i < end; i++ {
		if i%2 == 0 {
			Yield(i)
		}
	}
	return
}

func SampleGetNumList

func SampleGetNumList() (_ ʂɘʠ.Iterator[int])
func SampleGetNumList() (_ Iter[int]) {
	Yield(1)
	Yield(2)
	Yield(3)
	return
}

func SampleLoop

func SampleLoop() (_ ʂɘʠ.Iterator[any])
func SampleLoop() (_ Iter[any]) {
	for i := 0; i < 5; i++ {
		Yield(i)
	}

	xs := []string{"a", "b", "c"}
	for i, n := range xs {
		Yield(Pair[int, string]{i, n})
	}

	for i, c := range "Hello World!" {
		Yield(Pair[int, rune]{i, c})
	}
	return
}

func SampleLoopMap

func SampleLoopMap() (_ ʂɘʠ.Iterator[Pair[string, int]])
func SampleLoopMap() (_ Iter[Pair[string, int]]) {
	m := map[string]int{"a": 1, "b": 2, "c": 3}
	for k, v := range m {
		Yield(Pair[string, int]{k, v})
	}
	return
}

func SampleYieldFrom

func SampleYieldFrom() (_ ʂɘʠ.Iterator[int])
func SampleYieldFrom() (_ Iter[int]) {
	Yield(0)
	YieldFrom(SampleGetNumList())
	Yield(4)
	return
}

Types

type Line

type Line struct {
	Bytes  []byte
	Prefix bool
	Err    error
}

type Pair

type Pair[K, V any] struct {
	Key K
	Val V
}

Directories

Path Synopsis
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL