co

package module
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: 0 Imported by: 0

README ยถ

๐–๐ก๐š๐ญ ๐ข๐ฌ ๐•˜๐• -๐•”๐• 

๐™๐™๐™š ๐™Š๐™ก๐™™ ๐™‰๐™š๐™ฌ ๐™๐™๐™ž๐™ฃ๐™œ

golang co-routine is a source to source compiler which rewrites trival yield statements to monadic style code.

Inspired by wind-js.

Quick Start

Create source files ending with _co.go / _co_test.go.

Build tag //go:build co required.

Then go generate -tags co ./... (or run by IDE whatever).

And it is a good idea to switch custom build tag to co when working in goland or vscode, so IDE will be happy to index and check your code.

//go:build co

//go:generate go install github.com/goghcrow/go-co/cmd/cogen
//go:generate cogen

package main

import (
	. "github.com/goghcrow/go-co"
)

func Fibonacci() Iter[int] {
  a, b := 1, 1
  for {
    Yield(b)
    a, b = b, a+b
  }
}

func main() {
	for n := range Fibonacci() {
		if n > 1000 {
			println(n)
			break
		}
	}
}

Example

API

go get github.com/goghcrow/go-co@latest

package main

import (
    "github.com/goghcrow/go-co/rewriter"
    "github.com/goghcrow/go-loader"
)

func main() {
    rewriter.Compile(
        "./src",
        "./out",
        loader.WithLoadTest(),
    )
}

Control Flow Support

Rewrite control flow to monadic func invoking.

  • IfStmt
  • SwitchStmt
    • Fallthrough
  • TypeSwitchStmt
  • ForStmt
  • RangeStmt
    • string
    • slice
    • map
    • array
    • integer
    • channel
    • range func
  • BlockStmt
  • Break / Continue
    • Non-Label
    • Label
  • Goto
  • SelectStmt
  • DeferStmt

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

func Yield ยถ

func Yield[V any](V)

func YieldFrom ยถ

func YieldFrom[V any](Iter[V])

Types ยถ

type Iter ยถ

type Iter[V any] <-chan V

Iter is a ๐—ฆ๐˜†๐—ป๐˜๐—ฎ๐—ฐ๐˜๐—ถ๐—ฐ ๐—ฆ๐˜‚๐—ด๐—ฎ๐—ฟ please coding depending on the type parameter [V] instead of the underlying type <-chan

func (Iter[V]) Current ยถ

func (Iter[V]) Current() (_ V)

func (Iter[V]) MoveNext ยถ

func (Iter[V]) MoveNext() (_ bool)

Directories ยถ

Path Synopsis
cmd
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
lexer
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
linq
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
microthread
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
sched1
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
sched2
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
Code generated by github.com/goghcrow/go-co DO NOT EDIT.
tree
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