package jx

// begin should be called before new Array or Object.
func ( *Encoder) () {
	.first = append(.first, true)
}

// end should be called after Array or Object.
func ( *Encoder) () {
	if len(.first) == 0 {
		return
	}
	.first = .first[:.current()]
}

func ( *Encoder) () int { return len(.first) - 1 }

// comma should be called before any new value.
func ( *Encoder) () bool {
	// Writing commas.
	// 1. Before every field expect first.
	// 2. Before every array element except first.
	if len(.first) == 0 {
		return false
	}
	 := .current()
	_ = .first[]
	if .first[] {
		.first[] = false
		return false
	}
	return .byte(',') ||
		.writeIndent()
}