lof

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 1 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

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 IfNotEmpty added in v0.12.0

func IfNotEmpty(s string) (string, bool)

IfNotEmpty 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.IfNotEmpty(result); ok {
    t.Errorf("mismatch:\n%s", diff)
}

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