Skip to content

Instantly share code, notes, and snippets.

Last active Jul 26, 2021
What would you like to do?
My ReasonML gists

I was about to favor -> over |>

as of April, 2020 After reading this,, I thought I should use -> over |> for a performance reason.

by the way, the post was an excellent article 👍🏼

Wait, what are those symbols->, |>?

But the results of my experiment says it differently

You can see the experiment here.

The result looks same to me 🤷🏻‍♂️

but to be fair, it's a quite simple example, so I'm not sure how this will work with more complex examples

Anyway I'm guessing the compiler must have improved some optimizations on this over time.

Mix them with a care

Although you can mix them together, you might run into some issues, when you do in one chunk. An example is here

A tip for using -> for

if you want to stick with List instead of Belt.List when you want to use -> over |>

// this is 
[0, 1] -> => x + 1, _);
// basically doing the "same" thing as below:
[0, 1] |> => x + 1);

about using -> and f(..., _) together, it's thanks to pipe placeholders

Personal conclusion

I still prefer |> because of:

  1. formatting reasons
// I prefer this
a |> b |> c;
// over this
  1. Play nicer with standard module like List
  2. There seems to be no cost on JS side. (correct me if I'm wrong on this)

But I'm glad now I understand better about ->

I think I will use -> too in cases where it makes more sense to use over |>.

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