Should there be an example of map and forEach in the ReasonML cheatsheet docs?


#1

Would it be useful for beginners to a see an example of map and forEach in the cheatsheet if your are a beginner coming from JavaScript? :smile:

How did you find out the syntax for that?

JavaScript Reason
[1,2,3].forEach(i => { console.log(i) }) Array.iter(i => { Js.log(i) }, [|1,2,3|])
[1,2,3].map(i => { return i + 1 }) Array.map(i => i + 1, [|1,2,3|])

#2

I think that’s a good idea! I remember starting out that the typical map/filter/forEach/reduce workflow was one of the things that I found hard to figure out how to do in Reason.


#3

That was also myself a mystery, I know it is pretty typically for a functional language, but had not that much experience with that before reasonml.


#4

I think this would be a great addition. Please send a PR :slight_smile:


#5

I created a PR here with the examples :smile: https://github.com/reasonml/reasonml.github.io/pull/431


#6

Since the fast pipe and [@bs.send] align so well with method chaining, I wonder if it should be more idiomatic to go [| 1, 2, 3 |]->Array.map(i => i + 1) even when it’s a single call.


#7

Whoa, that was a while ago :slight_smile: I’ve been meaning to reach out to the team to see what can be done about the backlog.

@hoichi re: using fast-pipe like method access for a single call, I honestly am not able to judge at this point. If you were talking about pipe-forward (|>), I would say don’t use it unless you have at least two nested function calls, but with pipe-first I don’t have a clear idea of its idioms yet.