Skip to content

Optional Hackpipes proposal #198

Open
@webduvet

Description

@webduvet

The optional hackpipes proposal |?> caught my eye.

A short-circuiting optional-pipe operator |?> could also be useful, much in the way ?. is useful for optional method calls.

Instead of using |?> in any subsequent pipe in order to take care of undefined branch I would propose two constructs:

value |?> expr
value |*> expr

The rules

value |?> expr

Expresion would execute only if value us not undefined. If the input value is undefined It would skip the expression and continue to the next pipe.

value |*> expr

The second one would abort pipe if undefined value is passed thus leaving the final value of the composed structure undefined.

example:

value
  |?> one(^) // execute expression only if the input value is not undefined, otherwise skip to next pipe
  |*> two(^) // execute expression only if the input value is not undefined, otherwise abort pipe
  |> three(^) // this would execute only if the pipe is not aborted.

the above could be extended to get more granular control over pipes

value
  |?![null, false, myVar]> one(^) // execute only if passed value does not match any in the list (in addition to undefined) 
  |*![null, false, myVar]> one(^) // the same as above but abort the pipe
  |?[myVar, 34]> one(^) // execute only if value matches the listed values, otherwise skip
  |*[myVar, 34]> one(^) // execute only if value matches the listed values, otherwise abort the pipe

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfollow-on proposalDiscussion about a future follow-on proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions