Help us shape the future of Go! Take the 2026 Go Developer Survey

matchopt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package matchopt provides helpers for building Option-based pattern-match arms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alt

func Alt[A any](cases []O.Option[A]) O.Option[A]

Alt returns the first Some in cases, or None if all are None.

func Case

func Case[A, B any](
	pred func(A) bool,
	f func(A) B,
) func(A) O.Option[B]

Case builds a pattern arm: if pred holds, apply f and wrap in Some; else None.

func Const

func Const[A, B any](
	pred func(A) bool,
	value B,
) func(A) O.Option[B]

Const builds a pattern arm that yields a constant value when pred holds.

func Default

func Default[A, B any](f func(A) B) func(A) O.Option[B]

Default builds a catch-all arm that always matches and applies f.

func First

func First[A any](fallback A, cases []O.Option[A]) A

First returns the value of the first Some in cases, or fallback.

func Match

func Match[A, B any](
	fallback B,
	cases []O.Kleisli[A, B],
) func(A) B

Match lazily dispatches input to the first matching case in order, returning fallback when no case matches. Unlike First, which folds already-applied options, Match applies cases itself and stops invoking them at the first Some: later cases never run, so guard cost is not paid past the match.

Types

This section is empty.

Jump to

Keyboard shortcuts

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