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
CamelCaseโ
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]
// CompletedSimilar:Prototype:func CamelCase[T ~[]byte]()
KebabCaseโ
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]
// CompletedPrototype:func KebabCase[T ~[]byte]()
Capitalizeโ
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]
// CompletedSimilar:Prototype:func Capitalize[T ~[]byte]()
Ellipsisโ
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]
// CompletedSimilar:Prototype:func Ellipsis[T ~[]byte](length int)
PascalCaseโ
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]
// CompletedSimilar:Prototype:func PascalCase[T ~[]byte]()
Randomโ
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]
// CompletedSimilar:Prototype:func Random[T any](size int, charset []rune)
SnakeCaseโ
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]
// CompletedSimilar:Prototype:func SnakeCase[T ~[]byte]()
Wordsโ
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]]
// CompletedSimilar:Prototype:func Words[T ~[]byte]()