func (s ConcurrentSeq) Len() int {
	len := 0
	s.Find(func(el El)bool{
		len++;
		return false
	})
	return len
}
returns the length of s
package seq
import "fmt"
import "io"
import "os"
import "reflect"
type El interface{}
type Sequence struct {
	Seq
}
type Seq interface {
	Find(f func(i El)bool) El
	Rest() Sequence
	Len() int
	IsConcurrent() bool
}
func (s Sequence) Concurrent() Sequence {
	if s.IsConcurrent() {return s}
	return Gen(func(c SeqChan){s.Output(c)})
}
func (s Sequence) Sequential() Sequence {
	switch seq := s.Seq.(type) {case *SequentialSeq: return s}
	return s.SMap(func(el El)El{return el})
}
func (s Sequence) FirstN(n int) []interface{} {
	r := make([]interface{}, n)
	x := 0
	s.Find(func(el El)bool{
		r[x] = el
		x++
		return x == n
	})
	return r
}
func (s Sequence) First2() (a, b interface{}) {
	r := s.FirstN(2)
	return r[0], r[1]
}
func (s Sequence) First3() (a, b, c interface{}) {
	r := s.FirstN(3)
	return r[0], r[1], r[2]
}
func (s Sequence) First4() (a, b, c, d interface{}) {
	r := s.FirstN(4)
	return r[0], r[1], r[2], r[3]
}
func (s Sequence) First5() (a, b, c, d, e interface{}) {
	r := s.FirstN(5)
	return r[0], r[1], r[2], r[3], r[4]
}
func (s Sequence) First6() (a, b, c, d, e, f interface{}) {
	r := s.FirstN(6)
	return r[0], r[1], r[2], r[3], r[4], r[5]
}
func IsSeq(s interface{}) bool {
	_, test := s.(Seq)
	return test
}
func (s Sequence) First() interface{} {
	var result interface{}
	s.Find(func(el El)bool{
		result = el
		return true
	})
	return result
}
func (s Sequence) IsEmpty() bool {
	empty := true
	s.Find(func(el El)bool{
		empty = false
		return true
	})
	return empty
}
func (s Sequence) While(f func(el El) bool) {s.Find(func(el El)bool{return !f(el)})}
func (s Sequence) Do(f func(el El)) {
	s.Find(func(el El)bool{
		f(el)
		return false
	})
}
func (s Sequence) CDo(f func(el El), sizePowerOpt... uint) {
	c := s.CMap(func(el El)El{f(el); return nil}, sizePowerOpt...).Seq.(ConcurrentSeq)()
	for <- c; !closed(c); <- c {}
}
func (s Sequence) Output(c SeqChan) {s.Do(func(el El){c <- el})}
func (s1 Sequence) Append(s2 Sequence) Sequence {
	if s1.IsConcurrent() {return s1.CAppend(s2)}
	return s1.SAppend(s2)
}
func (s1 Sequence) Prepend(s2 Sequence) Sequence {
	if s1.IsConcurrent() {return s2.CAppend(s1)}
	return s2.SAppend(s1)
}
func (s Sequence) ToSlice() []interface{} {
	return *(*[]interface{})(s.Sequential().Seq.(*SequentialSeq))
}
func (s Sequence) SAppend(s2 Sequence) Sequence {
	slice := s.ToSlice()
	slice = append(slice, s2.ToSlice()...)
	return Sequence{(*SequentialSeq)(&slice)}
}
func (s Sequence) CAppend(s2 Sequence) Sequence {
	return Gen(func(c SeqChan){
		s.Output(c)
		s2.Output(c)
	})
}
func (s Sequence) quickLen(d int) int {
	switch seq := s.Seq.(type) {case *SequentialSeq: return s.Len()}
	return d
}
func (s Sequence) Filter(filter func(e El)bool) Sequence {
	if s.IsConcurrent() {return s.CFilter(filter)}
	return s.SFilter(filter)
}
func ifFunc(condition func(e El)bool, op func(e El)) func(el El){return func(el El){if condition(el) {op(el)}}}
func (s Sequence) SFilter(filter func(e El)bool) Sequence {
	slice := make([]interface{}, 0, s.quickLen(8))
	s.Do(ifFunc(filter, func(el El){slice = append(slice, el)}))
	return Sequence{(*SequentialSeq)(&slice)}
}
func (s Sequence) CFilter(filter func(e El)bool, sizePowerOpt... uint) Sequence {
	return Gen(func(c SeqChan){
		s.CDo(ifFunc(filter, func(el El){c <- el}), sizePowerOpt...)
	})
}
func (s Sequence) Map(f func(el El) El) Sequence {
	if s.IsConcurrent() {return s.CMap(f)}
	return s.SMap(f)
}
func (s Sequence) SMap(f func(i El)El) Sequence {
	slice := make([]interface{}, 0, s.quickLen(8))
	s.Do(func(el El){slice = append(slice, f(el))})
	return Sequence{(*SequentialSeq)(&slice)}
}
type reply struct {
	index int;
	result El
}
type swEntry struct {
	value El
	present bool
}
type SlidingWindow struct {
	start, base, count, mask int
	values []swEntry
}
func NewSlidingWindow(sz uint) *SlidingWindow {return &SlidingWindow{0, 0, 0, (1 << sz) - 1, make([]swEntry, 1 << sz)}}
func (r *SlidingWindow) Max() int {return r.base + len(r.values) - 1}
func (r *SlidingWindow) Capacity() int {return len(r.values)}
func (r *SlidingWindow) Count() int {return r.count}
func (r *SlidingWindow) normalize(index int) int {return (index + len(r.values)) & r.mask}
func (r *SlidingWindow) IsEmpty() bool {return r.count == 0}
func (r *SlidingWindow) IsFull() bool {return r.count == len(r.values)}
func (r *SlidingWindow) GetFirst() (interface{}, bool) {return r.values[r.start].value, r.values[r.start].present}
func (r *SlidingWindow) RemoveFirst() (interface{}, bool) {
	result := r.values[r.start]
	if !result.present {return nil, false}
	r.values[r.start] = swEntry{nil, false}
	r.count--
	r.start = r.normalize(r.start + 1)
	r.base++
	return result.value, true
}
func (r *SlidingWindow) Get(index int) (interface{}, bool) {
	index -= r.base
	if index < 0 || index >= r.Capacity() {return nil, false}
	index = r.normalize(index + r.start)
	value := r.values[index]
	return value.value, value.present
}
func (r *SlidingWindow) Set(index int, value interface{}) bool {
	index -= r.base
	if index < 0 || index >= r.Capacity() {return false}
	index = r.normalize(index + r.start)
	r.values[index].value = value
	if !r.values[index].present {
		r.values[index].present = true
		r.count++
	}
	return true
}
func (s Sequence) CMap(f func(el El) El, sizePowerOpt... uint) Sequence {
	sizePower := uint(6)
	if len(sizePowerOpt) > 0 {sizePower = sizePowerOpt[0]}
	size := 1 << sizePower
	return Gen(func(output SeqChan){
		input := s.Concurrent().Seq.(ConcurrentSeq)()
		window := NewSlidingWindow(sizePower)
		replyChannel := make(chan reply)
		inputCount, pendingInput := 0, 0
		inputClosed := false
		defer close(replyChannel)
		for !inputClosed || pendingInput > 0 || window.Count() > 0 {
			first, hasFirst := window.GetFirst()
			ic, oc, rc := input, output, replyChannel
			if !hasFirst {oc = nil}
			if inputClosed || pendingInput >= size {ic = nil}
			if window.Count() >= size {rc = nil}
			select {
			case oc <- first: window.RemoveFirst()
			case inputElement := <- ic:
				if closed(ic) {
					inputClosed = true
				} else {
					go func(index int, value interface{}) {
						replyChannel <- reply{index, f(value)}
					}(inputCount, inputElement)
					inputCount++
					pendingInput++
				}
			case replyElement := <- rc:
				window.Set(replyElement.index, replyElement.result)
				pendingInput--
			}
		}
	})
}
func (s Sequence) FlatMap(f func(el El) Sequence) Sequence {
	if s.IsConcurrent() {return s.CFlatMap(f)}
	return s.SFlatMap(f)
}
func (s Sequence) SFlatMap(f func(i El) Sequence) Sequence {
	slice := make([]interface{}, 0, s.quickLen(8))
	s.Do(func(e El){f(e).Do(func(sub El){slice = append(slice, sub)})})
	return Sequence{(*SequentialSeq)(&slice)}
}
func (s Sequence) CFlatMap(f func(i El) Sequence, sizePowerOpt... uint) Sequence {
	return Gen(func(c SeqChan){
		s.CMap(func(e El)El{return f(e)}, sizePowerOpt...).Do(func(sub El){
			sub.(Sequence).Output(c)
		})
	})
}
func (s Sequence) Fold(init interface{}, f func(acc, el El)El) interface{} {
	s.Do(func(el El){init = f(init, el)})
	return init
}
func (s Sequence) Combinations(number int) Sequence {
	if number == 0 || s.IsEmpty() {return From(From())}
	return s.Rest().Combinations(number).Prepend(s.Rest().Combinations(number - 1).Map(func(el El)El{
		return el.(Sequence).Prepend(From(s.First()))
	}))
}
func (sequences Sequence) Product() Sequence {
	return sequences.Fold(From(From()), func(result, each El)El{
		return result.(Sequence).FlatMap(func(seq El)Sequence{
			return each.(Sequence).Map(func(i El) El {
				return seq.(Sequence).Append(From(i))
			})
		})
	}).(Sequence)
}
func Prettyln(s interface{}, rest... interface{}) {
	writer := Pretty(s, rest...)
	fmt.Fprintln(writer)
}
func Pretty(s interface{}, args... interface{}) io.Writer {
	var writer io.Writer = os.Stdout
	var names map[interface{}]string
	for i := 0; i < len(args); i++ {
		switch arg := args[i].(type) {
		case map[interface{}]string: names = arg
		case io.Writer: writer = arg
		}
	}
	if names == nil {names = map[interface{}]string{}}
	prettyLevel(s, 0, names, writer)
	return writer
}
func hashable(v interface{}) bool {
	k := reflect.Typeof(v).Kind()
	return k < reflect.Array || k == reflect.Ptr || k == reflect.UnsafePointer
}
func getName(names map[interface{}]string, v interface{}) (string, bool) {
	switch s := v.(type) {case Sequence: v = s.Seq}
	if hashable(v) {
		kk, vv := names[v]
		return kk, vv
	}
	return "", false
}
func hasName(names map[interface{}]string, v interface{}) bool {
	_, has := getName(names, v)
	return has
}
func prettyLevel(s interface{}, level int, names map[interface{}]string, w io.Writer) {
	name, has := getName(names, s)
	if has {
		fmt.Fprint(w, name)
	} else switch arg := s.(type) {
	case Sequence: prettyLevel(arg.Seq, level, names, w)
	case Seq:
		fmt.Fprintf(w, "%*s%s", level, "", "[")
		first := true
		innerSeq := false
		named := false
		Sequence{arg}.Do(func(v El) {
			named = hasName(names, v)
			_,innerSeq = v.(Sequence)
			if first {
				first = false
				if !named && innerSeq {fmt.Fprintln(w)}
			} else if !named && innerSeq {
				fmt.Fprintln(w, ",")
			} else {
				fmt.Fprint(w, ", ")
			}
			if innerSeq {
				prettyLevel(v.(Sequence), level + 4, names, w)
			} else {
				fmt.Fprintf(w, "%v", v)
			}
		})
		if innerSeq {
			if !named {
				fmt.Fprintf(w, "\n%*s", level, "")
			}
		}
		fmt.Fprintf(w, "]")
	default:
		fmt.Print(arg)
	}
}
type SeqChan chan interface{}
type ConcurrentSeq func()SeqChan
func Gen(f func(c SeqChan)) Sequence {
	return Sequence{ConcurrentSeq(func() SeqChan {
		c := make(SeqChan)
		go func() {
			defer close(c)
			f(c)
		}()
		return c
	})}
}
func CUpto(limit int) Sequence {
	return Sequence(Gen(func(c SeqChan) {
		for i := 0; i < limit; i++ {
			c <- i
		}
	}))
}
func (s ConcurrentSeq) IsConcurrent() bool {return true}
func (s ConcurrentSeq) Find(f func(el El)bool) El {
	c := s()
	defer close(c)
	for el := <- c; !closed(c) ; el = <- c {
		if f(el) {return el}
	}
	return nil
}
func (s ConcurrentSeq) Rest() Sequence {
	return Sequence{ConcurrentSeq(func()SeqChan{
		c := s()
		<- c
		return c
	})}
}