Esempio n. 1
0
func (c *compositeConsumer) Consume(s functional.Stream) {
	consumers := make([]functional.Consumer, len(c.consumers))
	for i := range consumers {
		consumers[i] = c.consumers[i]
	}
	c.closeError = functional.MultiConsume(s, c.ptr, c.copier, consumers...)
}
Esempio n. 2
0
func main() {
	conn, err := sqlite.Open("chkbook.db")
	if err != nil {
		fmt.Println("Error opening file")
		return
	}
	s, err := ChkbkEntries(conn, 1)
	if err != nil {
		fmt.Printf("Error reading ledger %v", err)
	}
	expenseTotaler := &Totaler{}
	incomeTotaler := &Totaler{Income: true}
	printer := Printer{}
	err = functional.MultiConsume(s, new(Entry), nil, printer, expenseTotaler, incomeTotaler)
	if err != nil {
		fmt.Printf("Encountered error closing stream: %v", err)
	}
	fmt.Printf("Total income: %d\n", incomeTotaler.Total)
	fmt.Printf("Total expenses: %d\n", expenseTotaler.Total)
}