string

package
v2.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package string provides functional programming utilities for working with strings. It includes functions for string manipulation, comparison, conversion, and formatting, following functional programming principles with curried functions and composable operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ToUpperCase converts the string to uppercase
	ToUpperCase = strings.ToUpper

	// ToLowerCase converts the string to lowercase
	ToLowerCase = strings.ToLower

	// Ord implements the default ordering for strings
	Ord = ord.FromStrictCompare[string]()

	// Join joins strings
	Join = F.Curry2(F.Bind2nd[[]string, string, string])(strings.Join)

	// Equals returns a predicate that tests if a string is equal
	Equals = F.Curry2(Eq)

	// Includes returns a predicate that tests for the existence of the search string
	Includes = F.Bind2of2(strings.Contains)

	// HasPrefix returns a predicate that checks if the prefix is included in the string
	HasPrefix = F.Bind2of2(strings.HasPrefix)
)
View Source
var Monoid = M.MakeMonoid(concat, "")

Monoid is the monoid implementing string concatenation with empty string as identity

View Source
var Semigroup = S.MakeSemigroup(concat)

Semigroup is the semigroup implementing string concatenation

Functions

func Append added in v2.1.6

func Append(suffix string) func(string) string

Append returns a function that appends a suffix to a string. This is a curried function that takes a suffix and returns a function that appends that suffix to any string passed to it.

Example:

addExclamation := Append("!")
result := addExclamation("Hello") // "Hello!"

func Eq

func Eq(left, right string) bool

Eq tests if two strings are equal

func Format

func Format[T any](format string) func(T) string

Format applies a format string to an arbitrary value and returns a function that formats values of type T using the provided format string

func Intersperse

func Intersperse(middle string) func(string, string) string

Intersperse returns a function that concatenates two strings with a middle string in between. If either string is empty, the middle string is not added (to satisfy monoid identity laws).

func IntersperseMonoid

func IntersperseMonoid(middle string) M.Monoid[string]

IntersperseMonoid creates a monoid that concatenates strings with a middle string in between, with empty string as identity

func IntersperseSemigroup

func IntersperseSemigroup(middle string) S.Semigroup[string]

IntersperseSemigroup creates a semigroup that concatenates strings with a middle string in between

func IsEmpty

func IsEmpty(s string) bool

IsEmpty returns true if the string is empty

func IsNonEmpty

func IsNonEmpty(s string) bool

IsNonEmpty returns true if the string is not empty

func Prepend added in v2.1.6

func Prepend(prefix string) func(string) string

Prepend returns a function that prepends a prefix to a string. This is a curried function that takes a prefix and returns a function that prepends that prefix to any string passed to it.

Example:

addHello := Prepend("Hello, ")
result := addHello("World") // "Hello, World"

func Size

func Size(s string) int

Size returns the length of the string in bytes

func ToBytes

func ToBytes(s string) []byte

ToBytes converts a string to a byte slice

func ToRunes

func ToRunes(s string) []rune

ToRunes converts a string to a rune slice

Types

This section is empty.

Directories

Path Synopsis
Package generic provides generic string utility functions that work with any type that has string as its underlying type (using the ~string constraint).
Package generic provides generic string utility functions that work with any type that has string as its underlying type (using the ~string constraint).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL