lof

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 2 Imported by: 0

README

lof

Go builtins wrapped as passable functions for collection chains.

len and fmt.Println are operators, not functions — you can't pass them to higher-order methods. lof bridges the gap.

names.Each(lof.Println)

What It Looks Like

// Length of each inner slice — reports is [][]Page
pageCounts := slice.From(reports).ToInt(lof.Len)
// String lengths
charCounts := names.ToInt(lof.StringLen)

Operations

  • Len[T]([]T) int — wrap len for slices
  • StringLen(string) int — wrap len for strings
  • Println(string) — wrap fmt.Println
  • IsNonEmpty(string) bool — predicate for KeepIf on string slices
  • IfNonEmpty(string) (string, bool) — comma-ok for option.New

See pkg.go.dev for complete API documentation, the main README for installation, and slice for the collection methods that consume these wrappers.

Documentation

Overview

Package lof provides utility functions for functional programming.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IfNonEmpty added in v0.30.0

func IfNonEmpty(s string) (string, bool)

IfNonEmpty returns s and whether s is non-empty. Converts "empty string = absent" returns to Go's comma-ok idiom.

result := cmp.Diff(want, got)
if diff, ok := lof.IfNonEmpty(result); ok {
    t.Errorf("mismatch:\n%s", diff)
}

func IsNonBlank added in v0.30.0

func IsNonBlank(s string) bool

IsNonBlank returns true if s contains non-whitespace characters.

func IsNonEmpty added in v0.30.0

func IsNonEmpty(s string) bool

IsNonEmpty returns true if s is non-empty.

func Len

func Len[T any](ts []T) int

Len wraps the len builtin for slices.

func Println

func Println(s string)

Println wraps fmt.Println for strings.

func StringLen

func StringLen(s string) int

StringLen wraps the len builtin for strings.

Types

This section is empty.

Jump to

Keyboard shortcuts

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