Skip to content

Instantly share code, notes, and snippets.

@dangdennis
Created December 1, 2018 03:50
Show Gist options
  • Save dangdennis/e4b9b2a83d6b0408261f61ebd125b069 to your computer and use it in GitHub Desktop.
Save dangdennis/e4b9b2a83d6b0408261f61ebd125b069 to your computer and use it in GitHub Desktop.
/*
The fast pipe operator -> places the primary input in the FIRST argument position
Let's look at its use with Belt's List.map in a couple scenarios
*/
module FastPipe = {
/* Recall Belt's List.map signature
let map: (list('a), 'a => 'b) => list('b); */
let add5 = n => n + 5; /* callback func */
/* The list of integers are inserted as the first argument */
let listPlus5 = [1, 2, 3, 4, 5]->Belt.List.map(add5); /* [6,7,8,9,10] */
/* Common ReasonReact recipe for mapping over React elements */
let someMappedReasonElements =
["Text1", "Text2", "Text3"]
->Belt.List.map(text => <div> {ReasonReact.string(text)} </div>)
->Array.of_list
->ReasonReact.array;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment