Skip to main content
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!

Byte operatorsโ€‹

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

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(
    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
    Prototype:
    func CamelCase[T ~[]byte]()
  • Converts the string to kebab case.

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

    obs := ro.Pipe(
    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
    Prototype:
    func KebabCase[T ~[]byte]()
  • Capitalizes the first letter of the string.

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

    obs := ro.Pipe(
    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
    Prototype:
    func Capitalize[T ~[]byte]()
  • 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(
    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(
    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
    Prototype:
    func PascalCase[T ~[]byte]()
  • Generates a random string of specified size using charset.

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

    obs := ro.Pipe(
    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(
    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
    Prototype:
    func SnakeCase[T ~[]byte]()
  • Splits the string into words.

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

    obs := ro.Pipe(
    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]()