Skip to content

Pipe as lazy function #218

Description

@darky

Suggestion

⭐ Suggestion

pipe in FxTS works in eager fashion.

pipe(1, (n) => n + 1) // receiving of 2 immediately

Would be great to have something like pipeLazy, which works in lazy fashion.

const fn = pipeLazy((n: number) => n, n => n + 1) // Function<(n: number) => number>
fn(1) // 2

💻 Use Cases

  • Huge amount of FP libraries, that I know, using lazy pipe, not eager
  • Lazy pipes more JIT friendly and faster. They can be initialized once on application bootstrap and will works with maximum speed. Eager pipes will be generated every time and spend additional CPU resources.
  • Eager pipes increasing GC work much more than Lazy pipes, because lazy pipes can be initialized on application bootstrap and don't recreate pipe functions every time
  • Lazy pipes can be easily composed with each other.
  • Lazy pipes reduces pipe hell. Lazy pipes propagates to creating many little pipes. Eager pipes propagates to creating one big pipe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions