lof

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 1 Imported by: 0

README

lof: lower-order function wrappers

Wrap Go builtins for use with higher-order functions. When len or fmt.Println don't match the signature a HOF expects, lof provides compatible wrappers.

names.Each(lof.Println)  // print each name

Quick Start

import (
    "github.com/binaryphile/fluentfp/lof"
    "github.com/binaryphile/fluentfp/slice"
)

names := slice.From(users).ToString(User.Name)
names.Each(lof.Println)  // print each name

// When type has no Len() method, lof.Len bridges the gap
type Report struct { Pages []Page }

// pageCount returns the number of pages in a report.
pageCount := func(r Report) int { return lof.Len(r.Pages) }
pageCounts := slice.From(reports).ToInt(pageCount)

API Reference

Function Signature Purpose Example
Len Len[T]([]T) int Wrap len for slices lengths = items.ToInt(lof.Len)
StringLen StringLen(string) int Wrap len for strings lens = names.ToInt(lof.StringLen)
Println Println(string) Wrap fmt.Println names.Each(lof.Println)

When NOT to Use lof

  • Method expressions existUser.Name beats wrapping a getter
  • Direct calls work — If you're not in a HOF chain, just call len() or fmt.Println()

See Also

For the HOF methods that consume these wrappers, see slice.

Documentation

Overview

Package lof provides lower-order functions for use by higher-order functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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