# Killing \`Ok(())\` with \`ok!()\`

**URL:** <https://internals.rust-lang.org/t/killing-ok-with-ok/21915>\
**Category:** libs\
**Created:** [November 25, 2024, 2:38am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915 "2024-11-25T02:38:15Z")\
**Posts on this page:** 15\
**Page:** 3

<div class="post-metadata">

**Author:** ![FZs](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FZs](https://internals.rust-lang.org/u/FZs)\
**Post date:** [December 6, 2024, 6:54pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/41 "2024-12-06T18:54:28Z")

</div>

> [@phaylon](#):
>
> I know that there are people with different perspectives. But my experience is my experience. Disagreeing with it doesn't make it go away.

Of course. But note that I wrote "I disagree" and not "You're wrong". I did not try to invalidate your experience in any way, I just expressed my own, which is contrary to yours.

---

<div class="post-metadata">

**Author:** ![zackw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zackw/32/2071_2.png) [@zackw](https://internals.rust-lang.org/u/zackw)\
**Post date:** [December 6, 2024, 7:00pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/42 "2024-12-06T19:00:27Z")

</div>

I still believe we should have gone with method-like postfix `.await()` but that's not important right now! Also off-topic!

> [@tigregalis](#):
>
> something that's a little bit more generalised than `.wrap_ok()` and `.wrap_err()` etc. would just be `.wrap(Constructor)`

I actually thought of suggesting this when I posted my sample function. It generalizes better than anything else short of try blocks with auto-wrapping, _but_ if we do get those ([as suggested](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/34) above by @newpavlov), is there any remaining case where we'd still want `.wrap(Constructor)`?

(The name of any postfix wrapping method has to be totally new; it _is_ abstractly a map operation but we can't call it `.map` because that already means something else for so many existing types.)

---

<div class="post-metadata">

**Author:** ![binarycat](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/binarycat/32/12210_2.png) [@binarycat](https://internals.rust-lang.org/u/binarycat)\
**Post date:** [December 7, 2024, 6:33pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/43 "2024-12-07T18:33:21Z")

</div>

this "wrap" method is actually a function pipelineing operator (usually written `|>`) in disguise.

this operator is becoming increasingly popular in various languages, [existing in Unison](https://www.unison-lang.org/docs/fundamentals/values-and-functions/function-application-operators/), and being proposed for both [javascript](https://github.com/tc39/proposal-pipeline-operator/blob/main/README.md) and [nix](https://discourse.nixos.org/t/pre-rfc-pipe-operator/28387).

---

<div class="post-metadata">

**Author:** ![Ratatouille](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Ratatouille](https://internals.rust-lang.org/u/Ratatouille)\
**Post date:** [December 8, 2024, 4:20am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/44 "2024-12-08T04:20:44Z")

</div>

A generalized version of this was already proposed, the proposed syntax is x.(f)(\*) as syntactic sugar for f(x, \*).

(Maybe I will update the post with the link for the proposal later.)

---

<div class="post-metadata">

**Author:** ![HjVT](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hjvt/32/10365_2.png) [@HjVT](https://internals.rust-lang.org/u/HjVT)\
**Post date:** [December 8, 2024, 8:52am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/45 "2024-12-08T08:52:24Z")

</div>

I think the actual solution to "I want a free function in a chain of operations" would be to have a pipe composition operator.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [December 8, 2024, 1:56pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/46 "2024-12-08T13:56:07Z")

</div>

> [@zackw](#):
>
> (The name of any postfix wrapping method has to be totally new; it _is_ abstractly a map operation but we can't call it `.map` because that already means something else for so many existing types.)

Is it? `map`, to me, is about changing what's "in the box" (in monad speak) while this is changing (adding) the box itself. Haskell calls this `return` which is…taken. `wrap` certainly feels better to me.

---

<div class="post-metadata">

**Author:** ![tigregalis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tigregalis/32/12735_2.png) [@tigregalis](https://internals.rust-lang.org/u/tigregalis)\
**Post date:** [December 9, 2024, 3:17am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/47 "2024-12-09T03:17:02Z")

</div>

> [@Ratatouille](#):
>
> A generalized version of this was already proposed, the proposed syntax is x.(f)(\*) as syntactic sugar for f(x, \*).
> 
> (Maybe I will update the post with the link for the proposal later.)

So would this look like `some_value.(Ok)` or `some_value.(Ok)()`?

---

<div class="post-metadata">

**Author:** ![Ratatouille](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Ratatouille](https://internals.rust-lang.org/u/Ratatouille)\
**Post date:** [December 9, 2024, 5:16pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/48 "2024-12-09T17:16:27Z")

</div>

As promised, here is the link for the proposal:

> [@Weird syntax idea(s) for UMCS](https://internals.rust-lang.org/t/weird-syntax-idea-s-for-umcs/19200):
>
> UFCS: Unified Function Call Syntax, i.e. why you can do Type::method(&this, params). UMCS: Unified Method Call Syntax, i.e. allowing you to do foo.function(params) in some fashion for free function instead of requiring associated method lookup. Some sort of "pipe" operator has been considered desirable for a while, e.g. item |\> function(param) translating to function(item, param), potentially including autoref behavior. The thing is, Rust already has a "pipe" operator: the applicative .. The "o…

Regarding the question:

> [@tigregalis](#):
>
> So would this look like `some_value.(Ok)` or `some_value.(Ok)()`?

If I'm not mistaken, `val.(Ok)` creates a closure equivalent to `|| Ok(val)`. To actually execute the function and get `Ok(val)`, we need the trailing parentheses:`val.(Ok)()`.

---

<div class="post-metadata">

**Author:** ![Aloso](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/aloso/32/5039_2.png) [@Aloso](https://internals.rust-lang.org/u/Aloso)\
**Post date:** [December 9, 2024, 11:27pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/49 "2024-12-09T23:27:20Z")

</div>

> [@Ratatouille](#):
>
> the proposed syntax is x.(f)(\*) as syntactic sugar for f(x, \*)

I don't see why we should settle for this weird syntax instead of the pipelining operator `|>`, which looks much nicer:

```rust
something.(func)(args)
// vs
something |> func(args)

```

By the way, there is already a well-known crate for this, [tap](https://docs.rs/tap/latest/tap/). With its [`pipe`](https://docs.rs/tap/latest/tap/pipe/trait.Pipe.html#method.pipe) method, the above becomes

```rust
something.pipe(|x| func(x, args))

```

To wrap something in `Ok`, it is just

```rust
something.pipe(Ok)

```

---

<div class="post-metadata">

**Author:** ![parasyte](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/parasyte/32/8925_2.png) [@parasyte](https://internals.rust-lang.org/u/parasyte)\
**Post date:** [December 10, 2024, 9:32pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/50 "2024-12-10T21:32:44Z")

</div>

I kind of like pipelining as a general concept (even if I have very little use for it) but it doesn't seem to "kill Ok(())".

Compare:

```rust
Ok(())

().(Ok)()

() |> Ok

().pipe(Ok)

```

Syntactic differences aside, they are all more or less equivalent noise.

---

<div class="post-metadata">

**Author:** ![FZs](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FZs](https://internals.rust-lang.org/u/FZs)\
**Post date:** [December 10, 2024, 11:08pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/51 "2024-12-10T23:08:24Z")

</div>

The thread mostly steered away from "killing `Ok(())`", the pipeline was brought up for Ok-wrapping long chained expressions, not `()`.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jrose/32/9591_2.png) [@jrose](https://internals.rust-lang.org/u/jrose)\
**Post date:** [December 11, 2024, 12:22am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/52 "2024-12-11T00:22:38Z")

</div>

The downside of dedicated pipe-forward syntax like that is it’s not obvious where the input goes in the argument list. Nowhere else in Rust do we have argument lists that omit arguments that aren’t `self`.

Now of course you can say this is just one more piece of syntax to learn, which is true. We’d definitely get used to it, the way people get used to the method/function duality. But in a language without implicit currying, it’s not just another binary operator, at the very least.

---

<div class="post-metadata">

**Author:** ![Ratatouille](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Ratatouille](https://internals.rust-lang.org/u/Ratatouille)\
**Post date:** [December 11, 2024, 1:37pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/53 "2024-12-11T13:37:59Z")

</div>

I think the idea for proposing the syntax `x.(f)(*)` rather than `x |> f(*)` is from the observation that `.` is already a pipe operator, but one that works only on functions that we call "methods", and the idea is to naturally extend the existing operator rather than introducing a new one.

Furthermore, the `.` operator is arguably preferable, since it is more visually consistent. Consider the following:

```rust
x.method1(*)
 .method2(*)
 .(function)(*)
 .method3(*)

```

Chaining like this will look much less natural if you replace `.(function)(*)` with `.(function(*))` and especially with `|> function(*)`.

But regardless, I think that an agreement on whether some kind of pipe operator should be added is more important than argument about syntax.

> [@FZs](#):
>
> The thread mostly steered away from "killing `Ok(())`", the pipeline was brought up for Ok-wrapping long chained expressions, not `()`.

Maybe this conversation should be split into its own thread, with Ok-wrapping as one motivating use case?

---

<div class="post-metadata">

**Author:** ![mdHMUpeyf8yluPfXI](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mdHMUpeyf8yluPfXI](https://internals.rust-lang.org/u/mdHMUpeyf8yluPfXI)\
**Post date:** [December 12, 2024, 11:08am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/54 "2024-12-12T11:08:08Z")

</div>

It's the `map` for the identity functor. But I agree that calling it `map` can be confusing for people thinking more in kinds of boxes or containers.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [June 5, 2026, 11:08am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/55 "2026-06-05T11:08:59Z")

</div>

Closed on June 5, 2026, 11:08am UTC

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/killing-ok-with-ok/21915.md?page=2)
