Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Last active July 26, 2021 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/c8b74cace8b2ae4a87c3b553b7759529 to your computer and use it in GitHub Desktop.
Save ryuheechul/c8b74cace8b2ae4a87c3b553b7759529 to your computer and use it in GitHub Desktop.
My ReasonML gists

I was about to favor -> over |>

as of April, 2020 After reading this, https://www.javierchavarri.com/data-first-and-data-last-a-comparison/, 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 List.map

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

// this is 
[0, 1] -> List.map(x => x + 1, _);
// basically doing the "same" thing as below:
[0, 1] |> List.map(x => 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
a->b->c;
  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