Que fait fp-go-skill ?
Compétence Claude/Codex/Gemini pour fp-go/v2 - une bibliothèque de programmation fonctionnelle pour Go 1.24+, inspirée de fp-ts.
Aperçu
Cette compétence permet aux agents IA (Claude, Codex, Gemini) d'assister le développement avec la bibliothèque fp-go/v2. Elle couvre les principaux types, fonctions et patterns fonctionnels, y compris :
- Either : Gestion d'erreurs sans exceptions
- Option : Valeurs optionnelles (Some/None)
- Task : Calculs asynchrones
- IO : Effets de bord paresseux
- Reader : Injection de dépendances
- State : État immuable
- Pipe/Flow : Composition de fonctions
- Traversable : Parcours de structures de données
Types et fonctions clés
Either
import "github.com/fp-go/fp-go/v2/either"
type Either[L, R any] interface {
// implémentations privées
}
func Map[L, R, R2 any](f func(R) R2) func(Either[L, R]) Either[L, R2]
func Chain[L, R, R2 any](f func(R) Either[L, R2]) func(Either[L, R]) Either[L, R2]
func Fold[L, R any](onLeft func(L) R, onRight func(R) R) func(Either[L, R]) R
Option
import "github.com/fp-go/fp-go/v2/option"
type Option[A any] interface {
// implémentations privées
}
func Some[A any](value A) Option[A]
func None[A any]() Option[A]
func Map[A, B any](f func(A) B) func(Option[A]) Option[B]
func Chain[A, B any](f func(A) Option[B]) func(Option[A]) Option[B]
func Fold[A, B any](onNone func() B, onSome func(A) B) func(Option[A]) B
Task
import "github.com/fp-go/fp-go/v2/task"
type Task[A any] func() (A, error)
func Of[A any](a A) Task[A]
func Map[A, B any](f func(A) B) func(Task[A]) Task[B]
func Chain[A, B any](f func(A) Task[B]) func(Task[A]) Task[B]
Pipe et Flow
import "github.com/fp-go/fp-go/v2"
func Pipe[A, B any](a A, f func(A) B) B
func Flow[A, B, C any](f func(A) B, g func(B) C) func(A) C
Utilisation avec les agents IA
Pour utiliser cette compétence :
- Avec Claude Code : Inclure le fichier SKILL.md dans votre projet.
- Avec Codex : Ajouter la référence dans votre configuration.
- Avec Gemini : Passer le contenu de la compétence dans le contexte.
Exemple : Pipeline de validation
package main
import (
"github.com/fp-go/fp-go/v2"
"github.com/fp-go/fp-go/v2/either"
)
type User struct {
Name string
Email string
Age int
}
func validateName(name string) either.Either[error, string] {
if name == "" {
return either.Left[error, string](fmt.Errorf("le nom ne peut pas être vide"))
}
return either.Right[error, string](name)
}
func validateEmail(email string) either.Either[error, string] {
if !strings.Contains(email, "@") {
return either.Left[error, string](fmt.Errorf("email invalide"))
}
return either.Right[error, string](email)
}
func validateAge(age int) either.Either[error, int] {
if age < 0 || age > 150 {
return either.Left[error, int](fmt.Errorf("âge invalide"))
}
return either.Right[error, int](age)
}
func createUser(name string, email string, age int) either.Either[error, User] {
return fp.Pipe(
fp.Pipe(
validateName(name),
either.Map(func(n string) User { return User{Name: n} }),
),
either.Chain(func(u User) either.Either[error, User] {
return fp.Pipe(
validateEmail(email),
either.Map(func(e string) User { u.Email = e; return u }),
)
}),
either.Chain(func(u User) either.Either[error, User] {
return fp.Pipe(
validateAge(age),
either.Map(func(a int) User { u.Age = a; return u }),
)
}),
)
}
Ressources
- Documentation officielle de fp-go
- fp-ts - la bibliothèque TypeScript qui a inspiré fp-go
- Go 1.24 Release Notes