functor

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flap

func Flap[FAB ~func(A) B, A, B, HKTFAB, HKTB any](
	fmap func(func(FAB) B) func(HKTFAB) HKTB,
	a A,
) func(HKTFAB) HKTB

func Let

func Let[S1, S2, B, HKTS1, HKTS2 any](
	mmap func(func(S1) S2) func(HKTS1) HKTS2,
	key func(B) func(S1) S2,
	f func(S1) B,
) func(HKTS1) HKTS2

func LetTo

func LetTo[S1, S2, B, HKTS1, HKTS2 any](
	mmap func(func(S1) S2) func(HKTS1) HKTS2,
	key func(B) func(S1) S2,
	b B,
) func(HKTS1) HKTS2

func Map

func Map[A, B, HKTGA, HKTGB, HKTFGA, HKTFGB any](
	fmap func(func(HKTGA) HKTGB) func(HKTFGA) HKTFGB,
	gmap func(func(A) B) func(HKTGA) HKTGB,
	f func(A) B) func(HKTFGA) HKTFGB

func MonadFlap

func MonadFlap[FAB ~func(A) B, A, B, HKTFAB, HKTB any](
	fmap func(HKTFAB, func(FAB) B) HKTB,

	fab HKTFAB,
	a A,
) HKTB

func MonadLet

func MonadLet[S1, S2, B, HKTS1, HKTS2 any](
	mmap func(HKTS1, func(S1) S2) HKTS2,
	first HKTS1,
	key func(B) func(S1) S2,
	f func(S1) B,
) HKTS2

func MonadMap

func MonadMap[A, B, HKTGA, HKTGB, HKTFGA, HKTFGB any](
	fmap func(HKTFGA, func(HKTGA) HKTGB) HKTFGB,
	gmap func(HKTGA, func(A) B) HKTGB,
	fa HKTFGA,
	f func(A) B) HKTFGB

HKTFGA = HKT[F, HKT[G, A]] HKTFGB = HKT[F, HKT[G, B]]

Types

type Functor

type Functor[A, B, HKTA, HKTB any] interface {
	// Map transforms the value inside the functor using the provided function,
	// preserving the structure of the functor.
	//
	// Returns a function that takes a functor containing A and returns a functor containing B.
	Map(func(A) B) func(HKTA) HKTB
}

Functor represents a type that can be mapped over, allowing transformation of values contained within a context while preserving the structure of that context.

A Functor must satisfy the following laws:

Identity:

Map(identity) == identity

Composition:

Map(f ∘ g) == Map(f) ∘ Map(g)

Type Parameters:

  • A: The input value type contained in the functor
  • B: The output value type after transformation
  • HKTA: The higher-kinded type containing A (e.g., Option[A], Either[E, A])
  • HKTB: The higher-kinded type containing B (e.g., Option[B], Either[E, B])

Example:

// Given a functor for Option[int]
var f Functor[int, string, Option[int], Option[string]]
mapFn := f.Map(strconv.Itoa)
result := mapFn(Some(42)) // Returns Some("42")

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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