Skip to main content

string - Plugin operators

This page lists all operators available in the strings 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/strings
  • Converts string to camel case.

    import (
    "github.com/samber/ro"
    rostrings "github.com/samber/ro/plugins/strings"
    )

    obs := ro.Pipe[string, string](
    ro.Just("hello_world_world"),
    rostrings.CamelCase[string](),
    )

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

    // Next: helloWorldWorld
    // Completed
    Prototype:
    func CamelCase[T ~string]()
  • Capitalizes first letter of string.

    import (
    "github.com/samber/ro"
    rostrings "github.com/samber/ro/plugins/strings"
    )

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

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

    // Next: Hello world
    // Completed
    Prototype:
    func Capitalize[T ~string]()
  • Converts string to kebab case.

    import (
    "github.com/samber/ro"
    rostrings "github.com/samber/ro/plugins/strings"
    )

    obs := ro.Pipe[string, string](
    ro.Just("HelloWorldTest"),
    rostrings.KebabCase[string](),
    )

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

    // Next: hello-world-test
    // Completed
    Prototype:
    func KebabCase[T ~string]()
  • Truncates string to length with ellipsis.

    import (
    "github.com/samber/ro"
    rostrings "github.com/samber/ro/plugins/strings"
    )

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

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

    // Next: This is...
    // Completed
    Prototype:
    func Ellipsis[T ~string](length int)
  • Converts string to snake case.

    import (
    "github.com/samber/ro"
    rostrings "github.com/samber/ro/plugins/strings"
    )

    obs := ro.Pipe[string, string](
    ro.Just("HelloWorldWorld"),
    rostrings.SnakeCase[string](),
    )

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

    // Next: hello_world_world
    // Completed
    Prototype:
    func SnakeCase[T ~string]()
  • Splits string into words.

    import (
    "fmt"
    "github.com/samber/ro"
    rostrings "github.com/samber/ro/plugins/strings"
    )

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

    sub := obs.Subscribe(ro.NewObserver(
    func(words []string) {
    fmt.Printf("Next: %v\n", words)
    },
    func(err error) {
    fmt.Printf("Error: %v\n", err)
    },
    func() {
    fmt.Println("Completed")
    },
    ))
    defer sub.Unsubscribe()

    // Next: [hello world from go]
    // Completed
    Prototype:
    func Words[T ~string]()