fp-go-pipe-flow

Guides writing and refactoring fp-go v2 code using Pipe, Flow, reader monad, and do-notation patterns.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing functional Go code with the fp-go v2 library is error-prone because its combinators are low-frequency in training data, leading to misremembered signatures, wrong import paths, and imperative habits leaking into pipelines. This Skill provides verified patterns for Pipe, Flow, the reader monad, do-notation, and lenses so generated code compiles and follows fp-go idioms.

Core Features & Use Cases

  • Pipe and Flow composition: Apply data-first (Pipe) and function-first (Flow) composition correctly, with point-free style, Predicate/Endomorphism return types, and numeric combinators like N.MoreThan and N.Mul.
  • Reader monad and do-notation: Build environment-dependent computations with R.Do, R.Bind, R.ApS, and R.Let, choosing the right combinator for sequential versus independent steps.
  • Lenses and testing: Create lenses with L.MakeLens for struct field access and generate _test.go files that exercise pipelines with concrete environments and assert.Equal.
  • Use Case: A developer asks to refactor an imperative order-processing function into fp-go v2 style; the Skill produces a kleisli arrow using do-notation with Bind for database calls, Let for pure calculations, plus a unit test, all importing from github.com/IBM/fp-go/v2.

Quick Start

Refactor my imperative Go function into fp-go v2 style using Pipe, the reader monad with context.Context, and do-notation, and generate a unit test for it.

Frequently Asked Questions about fp-go-pipe-flow

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

FAQPage Schema
How do I compose functions with Pipe and Flow in fp-go v2?

Use F.PipeN when you already have a starting value to thread through N functions, and F.FlowN when building a reusable function to pass to Map, Chain, or TraverseArray. The numeric suffix matches the number of transformation steps, from Pipe1 up to Pipe26.

How do I use do-notation with the reader monad in fp-go?

Start with R.Do[Env](initialStruct) inside a Pipe, then add fields with R.Bind(setter, kleisli) for dependent steps, R.ApS(setter, reader) for independent ones, and R.Let for pure derived values. Setters and kleisli arrows should be named functions, never inline lambdas.

When should I use the reader monad versus a pure Flow pipeline?

Only use the reader monad when the computation genuinely needs an environment such as context.Context, config, or a database handle. For pure transformations with no external input, use Flow or Pipe directly without any reader wrapping.

Which import path should fp-go v2 code use?

All imports must come from github.com/IBM/fp-go/v2, never from the v1 path github.com/IBM/fp-go. Common aliases include F for function, R for reader, O for option, A for array, and L for optics/lens.

How do I test fp-go reader monad pipelines in Go?

Call the returned reader with a concrete lightweight environment struct rather than mocking it, then assert results with assert.Equal. For pure Flow or Pipe functions, invoke the returned function with a concrete value; prefer table-driven tests for multiple input/output pairs.