Skip to content

[fp-enhancer] Improve pkg/cli with functional transformations#12996

Closed
github-actions[bot] wants to merge 2 commits intomainfrom
main-9ab3a6fe170b8e15
Closed

[fp-enhancer] Improve pkg/cli with functional transformations#12996
github-actions[bot] wants to merge 2 commits intomainfrom
main-9ab3a6fe170b8e15

Conversation

@github-actions
Copy link
Contributor

Functional/Immutability Enhancements - Package: pkg/cli

This PR applies moderate, tasteful functional/immutability techniques to the pkg/cli package to improve code clarity, safety, testability, and maintainability.

Round-Robin Progress: This is part of a systematic package-by-package refactoring. Next package to process: pkg/cli/fileutil

Summary of Changes

Functional Transformations Applied

Converted 4 imperative loop patterns to declarative functional transformations using the existing sliceutil.Map utility:

  1. add_workflow_pr.go:85-88 - Extract workflow names
  2. audit_report_analysis.go:93-96 - Extract MCP server names
  3. add_command.go:220-223 - Extract workflow specs
  4. add_workflow_repository.go:90-93 - Convert WorkflowInfo to ListItems

Files affected:

  • pkg/cli/add_workflow_pr.go - Workflow name extraction
  • pkg/cli/audit_report_analysis.go - Server name extraction
  • pkg/cli/add_command.go - Workflow spec extraction
  • pkg/cli/add_workflow_repository.go - List item conversion

Benefits

  • Clarity: Declarative transformations make intent clearer ("what" not "how")
  • Consistency: Uses existing sliceutil.Map pattern established in the codebase
  • Simplicity: Eliminates index variables and reduces boilerplate
  • Maintainability: Functional patterns are easier to reason about
  • Safety: Pure transformations with no side effects

Principles Applied

  1. Declarative Over Imperative: Express transformations as "what" not "how"
  2. Use Existing Utilities: Leverage sliceutil.Map already in the codebase
  3. Tasteful Application: Only apply where it improves clarity
  4. Pragmatic Balance: No dogmatic functional programming - keep Go idiomatic

Testing

  • ✅ All CLI tests pass (go test ./pkg/cli/)
  • ✅ Test existence verified BEFORE refactoring (via code search)
  • ✅ Existing test suites cover all changed code
  • ✅ Binary builds successfully (make build)
  • ✅ No behavioral changes - functionality is identical

Review Focus

Please verify:

  • Functional transformations are appropriate for these use cases
  • Code clarity improved (declarative vs imperative)
  • No unintended behavior changes
  • Test coverage remains strong

Examples

Before: Imperative loop

workflowNames := make([]string, len(workflows))
for i, wf := range workflows {
    workflowNames[i] = wf.WorkflowName
}

After: Functional transformation

workflowNames := sliceutil.Map(workflows, func(wf *WorkflowSpec) string {
    return wf.WorkflowName
})

Benefits

  • More declarative - clearly expresses "extract names from workflows"
  • Eliminates index variable i
  • Uses well-tested sliceutil.Map utility
  • Easier to read and understand intent

Pattern Consistency

This change improves consistency with the functional patterns already established in the codebase:

  • pkg/sliceutil/sliceutil.go provides Map, Filter, Reduce, FilterMap
  • These utilities are used throughout the codebase for data transformations
  • Applying them to pkg/cli brings consistency with existing patterns

Impact Assessment

  • Risk: Low (pure transformations, no API changes)
  • Scope: 4 functions in pkg/cli package
  • Lines changed: 19 insertions, 19 deletions
  • Test impact: None (all tests pass)
  • Breaking changes: None

Workflow Run: §21548947321

AI generated by Functional Pragmatist

  • expires on Feb 7, 2026, 6:42 PM UTC

Apply tasteful functional programming improvements to pkg/cli:
- Replace imperative loops with declarative sliceutil.Map
- Eliminate index variables in simple transformations
- Improve code clarity and consistency

Changes:
- add_workflow_pr.go: Extract workflow names functionally
- audit_report_analysis.go: Extract server names functionally
- add_command.go: Extract workflow specs functionally
- add_workflow_repository.go: Convert to list items functionally

All tests pass (go test ./pkg/cli/)
@pelikhan
Copy link
Contributor

pelikhan commented Feb 1, 2026

@copilot merge main recompile

Copy link
Contributor

Copilot AI commented Feb 1, 2026

@pelikhan I've opened a new pull request, #13062, to work on those changes. Once the pull request is ready, I'll request review from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants