Skip to content

Suggestion: Pipe routing and merging abstraction. #189

@Enrico2

Description

@Enrico2

As I was working a lot with ro I notice that I often want to split a pipe into multiple subpipes, have different handling for each one, and then merge into an eventual result.

Consider, for example, handling a WebSocket events where each event has a different handler, but at the end of all handlers I converge into the same type.

Right now I do it manually and the code is cumbersome and involves some duplication of data which I'm not a fan of if it can be avoided (Especially when you consider pointers that would be shared by different branches of the pipe).

Here's a sketch of the idea:

import (
  "github.com/samber/mo"
  "github.com/samber/ro"
)

var input ro.Pipe[In, T] = ...

var handleX ro.Pipe[X, Out] = ...
var handleY ro.Pipe[Y, Out] = ...
var handleZ ro.Pipe[Z, Out] = ...

var router ro.PipeOp[In, mo.Either3[X, Y, Z]]

var result ro.Pipe[In, Out] = ro.Route3(
  input,
  router,
  handleX,
  handleY,
  handleZ,
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions