Skip to content

Imperative pipelines (“tap” operators) #741

Open

Description

@usaoc

Some languages provide pipeline operators or alike for use with imperative functions/methods:

  • Clojure provides doto that works like ->, except that each forms are evaluated and discarded, and the original value is returned. For example, (doto (new java.util.HashMap) (.put "a" 1) (.put "b" 2)) initiates a Java mutable hash table (see the ClojureDocs page).
  • In Kotlin, .apply (with receiver) and .also (with argument) are available as extension methods on objects (see Kotlin scope functions).
  • (Unfortunately, I couldn’t find a precedent on a .- or |>-like tap operator.)

This operation is also known as “tap” or “tee”. Is this a useful addition to Rhombus?

Activity

  1. samth commented on Dec 15, 2025

    @samth
    SponsorMember

    For doto: I think it's more useful to have the underlying API return the mutable object instead of void, which means just regular pipelines work properly.

  2. mflatt commented on Dec 15, 2025

    @mflatt
    Member

    FWIW, I experimented early on with having methods of mutable objects return the object, and I found it noisy (because results tend to get printed) and less clear than having Void as a result to highlight imperative behavior.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions