Documentation
¶
Index ¶
- func Atoi[T ~string]() func(ro.Observable[T]) ro.Observable[int]
- func FormatBool() func(ro.Observable[bool]) ro.Observable[string]
- func FormatComplex(mt byte, prec, bitSize int) func(ro.Observable[complex128]) ro.Observable[string]
- func FormatFloat(mt byte, prec, bitSize int) func(ro.Observable[float64]) ro.Observable[string]
- func FormatInt[T ~string](base int) func(ro.Observable[int64]) ro.Observable[string]
- func FormatUint[T ~string](base int) func(ro.Observable[uint64]) ro.Observable[string]
- func Itoa() func(ro.Observable[int]) ro.Observable[string]
- func ParseBool[T ~string]() func(ro.Observable[T]) ro.Observable[bool]
- func ParseFloat[T ~string](bitSize int) func(ro.Observable[T]) ro.Observable[float64]
- func ParseInt[T ~string](base int, bitSize int) func(ro.Observable[T]) ro.Observable[int64]
- func ParseUint[T ~string](base int, bitSize int) func(ro.Observable[T]) ro.Observable[uint64]
- func ParseUint64[T ~string](base int, bitSize int) func(ro.Observable[T]) ro.Observable[uint64]
- func Quote() func(ro.Observable[string]) ro.Observable[string]
- func QuoteRune() func(ro.Observable[rune]) ro.Observable[string]
- func Unquote() func(ro.Observable[string]) ro.Observable[string]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Atoi ¶
func Atoi[T ~string]() func(ro.Observable[T]) ro.Observable[int]
Atoi converts strings to integers using strconv.Atoi. Returns an error if the string cannot be converted to an integer.
Example:
ro.Pipe(ro.FromSlice([]string{"123", "456", "789"}), rostrconv.Atoi[string]()).
Subscribe(ro.NewObserver[int](...))
Play: https://go.dev/play/p/5hL9m8jK3nQ
Example ¶
// Convert strings to integers
observable := ro.Pipe1(
ro.Just("123", "456", "789"),
Atoi[string](),
)
subscription := observable.Subscribe(ro.PrintObserver[int]())
defer subscription.Unsubscribe()
Output: Next: 123 Next: 456 Next: 789 Completed
func FormatBool ¶
func FormatBool() func(ro.Observable[bool]) ro.Observable[string]
FormatBool converts boolean values to strings using strconv.FormatBool. Returns "true" for true values and "false" for false values.
Example:
ro.Pipe(ro.FromSlice([]bool{true, false, true}), rostrconv.FormatBool()).
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/8vDdaQyzoi_b
Example ¶
// Convert booleans to strings observable := ro.Pipe1( ro.Just(true, false, true), FormatBool(), ) subscription := observable.Subscribe(ro.PrintObserver[string]()) defer subscription.Unsubscribe()
Output: Next: true Next: false Next: true Completed
func FormatComplex ¶
func FormatComplex(mt byte, prec, bitSize int) func(ro.Observable[complex128]) ro.Observable[string]
FormatComplex converts complex128 values to strings with specified format, precision, and bit size. The format parameter (mt) can be:
'f' for fixed-point notation 'e' for scientific notation 'g' for the shortest representation
The prec parameter specifies the precision (number of digits). The bitSize parameter specifies the float type size (64 or 128).
Example:
ro.Pipe(ro.FromSlice([]complex128{3+4i, 1+2i}), rostrconv.FormatComplex('f', 2, 128)). // Fixed-point, 2 decimal places
Subscribe(ro.NewObserver[string](...))
func FormatFloat ¶
func FormatFloat(mt byte, prec, bitSize int) func(ro.Observable[float64]) ro.Observable[string]
FormatFloat converts float64 values to strings with specified format, precision, and bit size. The format parameter (mt) can be:
'f' for fixed-point notation 'e' for scientific notation 'g' for the shortest representation 'x' for hexadecimal notation
The prec parameter specifies the precision (number of digits). The bitSize parameter specifies the float type size (32 or 64).
Example:
ro.Pipe(ro.FromSlice([]float64{3.14159, 2.71828}), rostrconv.FormatFloat('f', 2, 64)). // Fixed-point, 2 decimal places
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/GWSPE4Mp-uy
Example ¶
// Convert floats to strings
observable := ro.Pipe1(
ro.Just(3.14159, 2.71828, 1.41421),
FormatFloat('f', 3, 64), // Format with 3 decimal places
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 3.142 Next: 2.718 Next: 1.414 Completed
func FormatInt ¶
func FormatInt[T ~string](base int) func(ro.Observable[int64]) ro.Observable[string]
FormatInt converts int64 values to strings with specified base. The base parameter determines the number system (e.g., 10 for decimal, 16 for hexadecimal).
Example:
ro.Pipe(ro.FromSlice([]int64{123, 456, 789}), rostrconv.FormatInt[string](16)). // Format as hexadecimal
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/hUpBVHRJgXY
Example ¶
// Convert integers to strings with different bases observable := ro.Pipe1( ro.Just(int64(255), int64(123), int64(456)), FormatInt[string](16), // Format as hex ) subscription := observable.Subscribe(ro.PrintObserver[string]()) defer subscription.Unsubscribe()
Output: Next: ff Next: 7b Next: 1c8 Completed
func FormatUint ¶
func FormatUint[T ~string](base int) func(ro.Observable[uint64]) ro.Observable[string]
FormatUint converts uint64 values to strings with specified base. The base parameter determines the number system (e.g., 10 for decimal, 16 for hexadecimal).
Example:
ro.Pipe(ro.FromSlice([]uint64{123, 456, 789}), rostrconv.FormatUint[string](16)). // Format as hexadecimal
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/h4TYG9sFPZw
Example ¶
// Convert unsigned integers to strings observable := ro.Pipe1( ro.Just(uint64(255), uint64(123), uint64(456)), FormatUint[string](10), // Format as decimal ) subscription := observable.Subscribe(ro.PrintObserver[string]()) defer subscription.Unsubscribe()
Output: Next: 255 Next: 123 Next: 456 Completed
func Itoa ¶
func Itoa() func(ro.Observable[int]) ro.Observable[string]
Itoa converts integers to strings using strconv.Itoa. This is equivalent to FormatInt with base 10.
Example:
ro.Pipe(ro.FromSlice([]int{123, 456, 789}), rostrconv.Itoa()).
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/6hN7k9jL4mR
Example ¶
// Convert integers to strings observable := ro.Pipe1( ro.Just(123, 456, 789), Itoa(), ) subscription := observable.Subscribe(ro.PrintObserver[string]()) defer subscription.Unsubscribe()
Output: Next: 123 Next: 456 Next: 789 Completed
func ParseBool ¶
func ParseBool[T ~string]() func(ro.Observable[T]) ro.Observable[bool]
ParseBool converts strings to boolean values using strconv.ParseBool. Accepts "1", "t", "T", "true", "TRUE", "True" for true values. Accepts "0", "f", "F", "false", "FALSE", "False" for false values. Returns an error if the string cannot be converted to a boolean.
Example:
ro.Pipe(ro.FromSlice([]string{"true", "false", "1", "0"}), rostrconv.ParseBool[string]()).
Subscribe(ro.NewObserver[bool](...))
Play: https://go.dev/play/p/2C5fkrRLyW_g
Example ¶
// Parse strings as booleans
observable := ro.Pipe1(
ro.Just("true", "false", "1", "0"),
ParseBool[string](),
)
subscription := observable.Subscribe(ro.PrintObserver[bool]())
defer subscription.Unsubscribe()
Output: Next: true Next: false Next: true Next: false Completed
func ParseFloat ¶
func ParseFloat[T ~string](bitSize int) func(ro.Observable[T]) ro.Observable[float64]
ParseFloat converts strings to float64 values with specified bit size. The bitSize parameter specifies the float type size (e.g., 32 for float32, 64 for float64). Returns an error if the string cannot be converted to a float.
Example:
ro.Pipe(ro.FromSlice([]string{"3.14", "2.718", "1.414"}), rostrconv.ParseFloat[string](64)). // Parse as 64-bit float
Subscribe(ro.NewObserver[float64](...))
Play: https://go.dev/play/p/g-YvtjXtX7V
Example ¶
// Parse strings as floats
observable := ro.Pipe1(
ro.Just("3.14", "2.718", "1.414"),
ParseFloat[string](64), // Parse as 64-bit float
)
subscription := observable.Subscribe(ro.PrintObserver[float64]())
defer subscription.Unsubscribe()
Output: Next: 3.14 Next: 2.718 Next: 1.414 Completed
func ParseInt ¶
func ParseInt[T ~string](base int, bitSize int) func(ro.Observable[T]) ro.Observable[int64]
ParseInt converts strings to int64 values with specified base and bit size. The base parameter determines the number system (e.g., 10 for decimal, 16 for hexadecimal). The bitSize parameter specifies the integer type size (e.g., 32 for int32, 64 for int64). Returns an error if the string cannot be converted to the specified integer type.
Example:
ro.Pipe(ro.FromSlice([]string{"123", "FF", "1010"}), rostrconv.ParseInt[string](16, 64)). // Parse as hex, 64-bit
Subscribe(ro.NewObserver[int64](...))
Play: https://go.dev/play/p/CqjCmQVAPXC
Example ¶
// Parse strings as integers with different bases
observable := ro.Pipe1(
ro.Just("123", "FF", "1010"),
ParseInt[string](16, 64), // Parse as hex, 64-bit
)
subscription := observable.Subscribe(ro.PrintObserver[int64]())
defer subscription.Unsubscribe()
Output: Next: 291 Next: 255 Next: 4112 Completed
Example (WithError) ¶
// Parse strings with potential errors
observable := ro.Pipe1(
ro.Just("123", "abc", "456"), // "abc" will cause an error
ParseInt[string](10, 64),
)
subscription := observable.Subscribe(ro.PrintObserver[int64]())
defer subscription.Unsubscribe()
Output: Next: 123 Error: strconv.ParseInt: parsing "abc": invalid syntax
func ParseUint ¶
func ParseUint[T ~string](base int, bitSize int) func(ro.Observable[T]) ro.Observable[uint64]
ParseUint converts strings to uint64 values with specified base and bit size. The base parameter determines the number system (e.g., 10 for decimal, 16 for hexadecimal). The bitSize parameter specifies the integer type size (e.g., 32 for uint32, 64 for uint64). Returns an error if the string cannot be converted to the specified unsigned integer type.
Example:
ro.Pipe(ro.FromSlice([]string{"123", "FF", "1010"}), rostrconv.ParseUint[string](16, 64)). // Parse as hex, 64-bit unsigned
Subscribe(ro.NewObserver[uint64](...))
Example ¶
// Parse strings as unsigned integers
observable := ro.Pipe1(
ro.Just("123", "456", "789"),
ParseUint[string](10, 64), // Parse as decimal, 64-bit unsigned
)
subscription := observable.Subscribe(ro.PrintObserver[uint64]())
defer subscription.Unsubscribe()
Output: Next: 123 Next: 456 Next: 789 Completed
func ParseUint64 ¶
func ParseUint64[T ~string](base int, bitSize int) func(ro.Observable[T]) ro.Observable[uint64]
ParseUint64 is an alias for ParseUint that specifically returns uint64. It provides the same functionality as ParseUint with bitSize=64.
Example:
ro.Pipe(ro.FromSlice([]string{"123", "456", "789"}), rostrconv.ParseUint64[string](10, 64)). // Parse as decimal, 64-bit unsigned
Subscribe(ro.NewObserver[uint64](...))
func Quote ¶
func Quote() func(ro.Observable[string]) ro.Observable[string]
Quote converts strings to Go string literals using strconv.Quote. This adds double quotes and escapes special characters.
Example:
ro.Pipe(ro.FromSlice([]string{"hello", "world\n", "test"}), rostrconv.Quote()).
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/O72Y-oUwBxr
Example ¶
// Quote strings
observable := ro.Pipe1(
ro.Just("hello", "world", "golang"),
Quote(),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: "hello" Next: "world" Next: "golang" Completed
func QuoteRune ¶
func QuoteRune() func(ro.Observable[rune]) ro.Observable[string]
QuoteRune converts runes to Go character literals using strconv.QuoteRune. This adds single quotes and escapes special characters.
Example:
ro.Pipe(ro.FromSlice([]rune{'a', 'b', 'c'}), rostrconv.QuoteRune()).
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/tCnviYGuSMn
Example ¶
// Quote runes
observable := ro.Pipe1(
ro.Just('a', 'b', 'c'),
QuoteRune(),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 'a' Next: 'b' Next: 'c' Completed
func Unquote ¶
func Unquote() func(ro.Observable[string]) ro.Observable[string]
Unquote converts Go string literals back to strings using strconv.Unquote. This removes quotes and unescapes special characters. Returns an error if the string is not a valid Go string literal.
Example:
ro.Pipe(ro.FromSlice([]string{`"hello"`, `"world\n"`, `"test"`}), rostrconv.Unquote()).
Subscribe(ro.NewObserver[string](...))
Play: https://go.dev/play/p/cMaHM-He8NT
Example ¶
// Unquote strings observable := ro.Pipe1( ro.Just(`"hello"`, `"world"`, `"golang"`), Unquote(), ) subscription := observable.Subscribe(ro.PrintObserver[string]()) defer subscription.Unsubscribe()
Output: Next: hello Next: world Next: golang Completed
Types ¶
This section is empty.