Documentation
¶
Overview ¶
Package strutils provides utility functions for string operations using fp-go functional patterns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 "".
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.
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
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 ¶
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
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))
Types ¶
This section is empty.