Skip to main content

Byte - Plugin operators

This page lists all operators available in the bytes sub-package of ro.

Help improve this documentation

This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.

Your feedback helps us improve!

Installโ€‹

First, import the sub-package in your project:

go get -u github.com/samber/ro/plugins/bytes
  • Converts the string to camel case.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("hello_world_world")),
    robytes.CamelCase[[]byte](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [104 101 108 108 111 87 111 114 108 100 87 111 114 108 100]
    // Completed

    CamelCaseWithLanguage

    Converts the string to camel case using locale-aware casing.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    "golang.org/x/text/language"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("Istanbul city")),
    robytes.CamelCaseWithLanguage[[]byte](language.Turkish),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [196 177 115 116 97 110 98 117 108 67 105 116 121]
    // Completed
    Prototypes:
    func CamelCase[T ~[]byte]()
    func CamelCaseWithLanguage[T ~[]byte](tag language.Tag)
  • Converts the string to kebab case.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("HelloWorldWorld")),
    robytes.KebabCase[[]byte](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [104 101 108 108 111 45 119 111 114 108 100 45 119 111 114 108 100]
    // Completed

    KebabCaseWithLanguage

    Converts the string to kebab case using locale-aware casing.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    "golang.org/x/text/language"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("IstanbulCity")),
    robytes.KebabCaseWithLanguage[[]byte](language.Turkish),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [196 177 115 116 97 110 98 117 108 45 99 105 116 121]
    // Completed
    Prototypes:
    func KebabCase[T ~[]byte]()
    func KebabCaseWithLanguage[T ~[]byte](tag language.Tag)
  • Capitalizes the first letter of the string.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("hello world")),
    robytes.Capitalize[[]byte](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [72 101 108 108 111 32 119 111 114 108 100]
    // Completed

    CapitalizeWithLanguage

    Capitalizes the first letter using locale-aware casing.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    "golang.org/x/text/language"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("istanbul")),
    robytes.CapitalizeWithLanguage[[]byte](language.Turkish),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [196 176 115 116 97 110 98 117 108]
    // Completed
    Prototypes:
    func Capitalize[T ~[]byte]()
    func CapitalizeWithLanguage[T ~[]byte](tag language.Tag)
  • Truncates the string to specified length and appends "..." if longer.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("This is a very long string")),
    robytes.Ellipsis[[]byte](10),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [84 104 105 115 32 105 115 32 46 46 46]
    // Completed
    Prototype:
    func Ellipsis[T ~[]byte](length int)
  • Converts the string to pascal case.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("hello_world_world")),
    robytes.PascalCase[[]byte](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [72 101 108 108 111 87 111 114 108 100 87 111 114 108 100]
    // Completed

    PascalCaseWithLanguage

    Converts the string to pascal case using locale-aware casing.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    "golang.org/x/text/language"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("istanbul city")),
    robytes.PascalCaseWithLanguage[[]byte](language.Turkish),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [196 176 115 116 97 110 98 117 108 67 105 116 121]
    // Completed
    Prototypes:
    func PascalCase[T ~[]byte]()
    func PascalCaseWithLanguage[T ~[]byte](tag language.Tag)
  • Generates a random string of specified size using charset.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[int, []byte](
    ro.Just(1, 2, 3),
    robytes.Random[int](10, []rune("abcdefghijklmnopqrstuvwxyz")),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [some random bytes]
    // Next: [some random bytes]
    // Next: [some random bytes]
    // Completed
    Prototype:
    func Random[T any](size int, charset []rune)
  • Converts the string to snake case.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("HelloWorldWorld")),
    robytes.SnakeCase[[]byte](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [104 101 108 108 111 95 119 111 114 108 100 95 119 111 114 108 100]
    // Completed

    SnakeCaseWithLanguage

    Converts the string to snake case using locale-aware casing.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    "golang.org/x/text/language"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("IstanbulCity")),
    robytes.SnakeCaseWithLanguage[[]byte](language.Turkish),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [196 177 115 116 97 110 98 117 108 95 99 105 116 121]
    // Completed
    Prototypes:
    func SnakeCase[T ~[]byte]()
    func SnakeCaseWithLanguage[T ~[]byte](tag language.Tag)
  • Splits the string into words.

    import (
    "github.com/samber/ro"
    robytes "github.com/samber/ro/plugins/bytes"
    )

    obs := ro.Pipe[[]byte, []byte](
    ro.Just([]byte("hello world from go")),
    robytes.Words[[]byte](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[][]byte]())
    defer sub.Unsubscribe()

    // Next: [[104 101 108 108 111] [119 111 114 108 100] [102 114 111 109] [103 111]]
    // Completed
    Prototype:
    func Words[T ~[]byte]()