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) []byte

Parameters & Attributes

NameTypeDescription
mappingfunc(r rune) runeFunction returning a replacement rune; negative removes the input rune.
s[]byteInput 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!"))))}
Go Reference