fp-go

Generates and reviews Go code using the fp-go v2 functional programming library.

2.0k|83|Updated Jul 5, 2023
One-click install
npx skills add https://github.com/IBM/fp-go --skill fp-go
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fp-go
Source: https://github.com/IBM/fp-go/tree/main/gen/v2/data/skills/fp-go
Command: npx skills add https://github.com/IBM/fp-go --skill fp-go

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing functional Go code with the fp-go v2 library is error-prone because its data-last API, leading type parameters, and monad selection rules are easy to misremember, and the library is underrepresented in training data. This Skill encodes the correct patterns so generated code compiles and follows fp-go idioms.

Core Features & Use Cases

  • Correct code generation rules: Enforces the v2 import path, data-last composition, non-inferrable leading type parameters, and point-free style with Flow and Pipe.
  • Monad selection guidance: Maps use cases to Option, Result, IOResult, ReaderIOResult, and Effect, including typed dependency injection for production services.
  • Do-notation patterns: Covers Bind, ApS, Let, LetTo, and BindTo with lens-based setters for accumulating multiple intermediate results.
  • Use Case: Convert idiomatic Go error handling with if-err boilerplate into a functional pipeline using result.Eitherize1, Chain, and GetOrElse, then verify it with go build and go vet.

Quick Start

Use the fp-go skill to refactor this Go function's error handling into a Result-based pipeline with Flow composition.

Frequently Asked Questions about fp-go

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use fp-go for error handling in Go?

Use the result package, where Result[A] is Either[error, A]. Lift Go functions returning (A, error) with result.Eitherize1, compose them with Chain and Map in data-last pipelines, and extract values with GetOrElse.

What is the difference between fp-go v1 and v2 import paths?

fp-go v2 uses the import path github.com/IBM/fp-go/v2 and requires Go 1.24 or later for generic type alias support. The v1 path github.com/IBM/fp-go is the older version and should not be used for new code.

When should I use Effect instead of ReaderIOResult in fp-go?

Use Effect[C, A] when your service has typed dependencies like database clients, HTTP clients, or config structs. It provides compile-time dependency checking and easy mocking, while ReaderIOResult only threads context.Context.

Why does my fp-go code fail to compile with Map?

Common causes are data-first argument order and wrong type parameter placement. fp-go is data-last, so write option.Map(f)(value), and non-inferrable type parameters come first, as in Map[B, A].

Should I use Bind or ApS in fp-go do-notation?

Use Bind when the step needs to read previously accumulated state, since its function receives the current state. Use ApS for independent steps, where the monadic value is fixed and does not depend on prior results.

What are the idiomatic packages in fp-go?

The idiomatic/ packages use Go-native tuples like (A, error) instead of struct wrappers, offering better performance and zero allocations. Use them in hot paths, but do not mix them with standard packages in one file since the types do not interoperate.