Standard library / bytes
bytes.Map()
Applies mapping to decoded runes and drops runes mapped to negative values. Expected stdout: 'GO\n'.
Formal Syntax & Structure
go syntaxgo
func Map(mapping func(r rune) rune, s []byte) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| mapping | func(r rune) rune | Function returning a replacement rune; negative removes the input rune. |
| s | []byte | Input text or sequence. |
Return Value
[]byte
Applies mapping to decoded runes and drops runes mapped to negative values.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "unicode")
func main() { fmt.Println(string(bytes.Map(func(r rune) rune { if r == '!' { return -1 } return unicode.ToUpper(r) }, []byte("go!"))))}