Overload pipe function to enable pipe syntax in lambda functions for library APIs#13
Overload pipe function to enable pipe syntax in lambda functions for library APIs#13Copilot wants to merge 5 commits into
Conversation
…ocumentation Co-authored-by: irony <395843+irony@users.noreply.github.com>
Co-authored-by: irony <395843+irony@users.noreply.github.com>
Co-authored-by: irony <395843+irony@users.noreply.github.com>
|
@copilot could we overload the pipe function instead of having a separate pipeFn? |
There was a problem hiding this comment.
Pull Request Overview
This PR implements a pipeFn helper function that enables pipeline-style syntax for library configuration, directly addressing the Hacker News comment asking about utility for expressions like v => v | trim | truncate | bold. The implementation adds a minimal 7-line function that wraps arrow functions containing pipe expressions, making them callable as regular async functions.
- Added
pipeFnhelper function to enable pipe syntax within arrow functions for library APIs - Comprehensive test suite with 6 new test cases covering various use scenarios
- Documentation updates with examples and new example files demonstrating real-world usage
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| index.js | Adds the core pipeFn implementation and exports it |
| test.js | Adds 6 comprehensive test cases covering string formatting, validation, numeric operations, arrays, async operations, and library simulation |
| README.md | Updates documentation with pipeFn API details, usage examples, and library use case section |
| library-example.js | Comprehensive example file demonstrating various pipeFn use cases including grid formatting and form validation |
| hn-comment-example.js | Direct implementation of the exact syntax from the Hacker News comment |
| PIPEFN-SUMMARY.md | Implementation summary document explaining the feature, benefits, and test coverage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: irony <395843+irony@users.noreply.github.com>
Done! Overloaded the |
Overview
This PR overloads the
pipefunction to enable the use of pipe syntax inside lambda functions, making it perfect for library configuration APIs. This addresses the question posed in this Hacker News comment about whether asPipes could support this pattern:Solution
The
pipefunction now detects when it's called with a function argument and automatically creates a pipeable function, eliminating the need for a separatepipeFnhelper. This provides a cleaner, more intuitive API:Implementation
The
pipefunction now checks the type of its argument:Benefits for Library Authors
pipefunction instead of separatepipeandpipeFnChanges
pipefunction inindex.jsto detect function argumentspipeFnexport (cleaner API with justpipe,asPipe, andtake)pipe(all 50 tests passing)library-example.jsto usepipeinstead ofpipeFnhn-comment-example.jsto usepipeinstead ofpipeFnExample Use Cases
Form validation:
Data formatting:
Data transformation:
Backward Compatibility
✅ Zero breaking changes - all existing tests continue to pass
✅ Fully backward compatible with existing
pipe(value)andasPipeusage✅ Cleaner exports:
{ pipe, asPipe, take }instead of{ pipe, asPipe, take, pipeFn }Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.