MoonBit io: provide simplified I/O abstractions similar to Go.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.$ moon version --all
moon 0.1.20250612 (2a026e0 2025-06-12) ~/.moon/bin/moon
moonc v0.1.20250612+600461c34 ~/.moon/bin/moonc
moonrun 0.1.20250612 (2a026e0 2025-06-12) ~/.moon/bin/moonruntype Bufferimpl ByteReader for Buffertype Discardpub(all) type! IOError String
type LimitedReaderimpl Reader for LimitedReadertype NopClosertype OffsetWritertype SectionReadertype Slice[T] http://www.apache.org/licenses/LICENSE-2.0let sum = [1, 2, 3, 4, 5][:].fold(init=0, fn { sum, elem => sum + elem })
sum // 15let sum = [1, 2, 3, 4, 5][:].foldi(init=0, fn { index, sum, elem => sum + index })
sum // 10let sum = [1, 2, 3, 4, 5][:].rev_fold(init=0, fn { sum, elem => sum + elem })
sum // 15let sum = [1, 2, 3, 4, 5][:].rev_foldi(~init=0, fn { index, sum, elem => sum + index })
sum // 10type TeeReaderlet sum = [1, 2, 3, 4, 5][:].fold(init=0, fn { sum, elem => sum + elem })
sum // 15let sum = [1, 2, 3, 4, 5][:].foldi(init=0, fn { index, sum, elem => sum + index })
sum // 10let sum = [1, 2, 3, 4, 5][:].rev_fold(init=0, fn { sum, elem => sum + elem })
sum // 15let sum = [1, 2, 3, 4, 5][:].rev_foldi(~init=0, fn { index, sum, elem => sum + index })
sum // 10