strutils

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package strutils provides utility functions for string operations using fp-go functional patterns.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Space joins with " ".
	Space = S.IntersperseMonoid(" ")

	// Comma joins with ", ".
	Comma = S.IntersperseMonoid(", ")

	// Semicolon joins with "; ".
	Semicolon = S.IntersperseMonoid("; ")

	// Colon joins with ":" and no space, as in "74:1-10".
	Colon = S.IntersperseMonoid(":")

	// Label joins a label and a value with ": ".
	Label = S.IntersperseMonoid(": ")

	// MiddleDot joins with " · ".
	MiddleDot = S.IntersperseMonoid(" · ")

	// EmDash joins with " — ".
	EmDash = S.IntersperseMonoid(" — ")

	// Newline joins with "\n".
	Newline = S.IntersperseMonoid("\n")
)

Separator monoids. Each one joins two strings with its separator and is built on [S.IntersperseMonoid], so an empty operand drops out together with its separator:

Comma.Concat("a", "b") // "a, b"
Comma.Concat("a", "")  // "a"

That makes an optional part (a missing DOI, an absent label) disappear with no branch. Empty() is "".

View Source
var (
	// JoinSpace joins a slice with " ".
	JoinSpace = M.ConcatAll(Space)

	// JoinComma joins a slice with ", ".
	JoinComma = M.ConcatAll(Comma)

	// JoinSemicolon joins a slice with "; ".
	JoinSemicolon = M.ConcatAll(Semicolon)

	// JoinMiddleDot joins a slice with " · ".
	JoinMiddleDot = M.ConcatAll(MiddleDot)

	// JoinLines joins a slice with "\n".
	JoinLines = M.ConcatAll(Newline)
)

Folds over the separator monoids. Each one joins a slice and skips empty elements together with their separators.

View Source
var (
	// CollapseWhitespace trims s and replaces every run of
	// whitespace, including newlines, with one space.
	CollapseWhitespace = F.Flow2(strings.Fields, JoinSpace)

	// Parens wraps s in "(" and ")".
	Parens = Wrap("(", ")")

	// Brackets wraps s in "[" and "]".
	Brackets = Wrap("[", "]")

	// Quote wraps s in double quotes. It does not escape s.
	Quote = Wrap(`"`, `"`)

	// Period appends ".".
	Period = S.Append(".")
)

Functions

func ConcatFields added in v0.3.0

func ConcatFields[A any](
	m M.Monoid[string],
) func([]func(A) string) func(A) string

ConcatFields lifts m to functions with [M.FunctionMonoid] and folds the projections into one function. Each projection renders one field of A, and m joins the results:

name := ConcatFields[Author](Space)(
	[]func(Author) string{lastName, initials},
)
name(Author{"Smith", "A"}) // "Smith A"

func JoinStrings

func JoinStrings(parts ...string) string

JoinStrings joins multiple strings using the fp-go string monoid via [A.Fold]. It is a variadic wrapper around folding the parts with [S.Monoid].

func MapNonEmpty added in v0.3.0

func MapNonEmpty(f func(string) string) func(string) string

MapNonEmpty applies f to a non-empty string and returns "" for an empty one. Combine it with a separator monoid to render an optional part: the empty result drops out with its separator.

link := MapNonEmpty(toDOILink)
MiddleDot.Concat(pubmed, link(doi))

func Wrap added in v0.3.0

func Wrap(prefix, suffix string) func(string) string

Wrap returns a function that puts prefix before and suffix after its argument.

Types

This section is empty.

Jump to

Keyboard shortcuts

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