Skip to content

Instantly share code, notes, and snippets.

@namenu
Created January 17, 2022 15:02
Show Gist options
  • Save namenu/568e0e3ec55867396b544378f84dcc63 to your computer and use it in GitHub Desktop.
Save namenu/568e0e3ec55867396b544378f84dcc63 to your computer and use it in GitHub Desktop.
Resx proposal
module Array = {
let map = (xs: array<'a>, f: 'a => React.element): React.element => {
Belt.Array.map(xs, f)->React.array
}
let mapWithIndex = (xs: array<'a>, f: (int, 'a) => React.element): React.element => {
Belt.Array.mapWithIndex(xs, f)->React.array
}
}
module Option = {
let get = (x: option<React.element>): React.element => {
Belt.Option.getWithDefault(x, React.null)
}
let map = (x: option<'a>, f: 'a => React.element): React.element => {
Belt.Option.mapWithDefault(x, React.null, f)
}
let flatMap = (x: option<'a>, f: 'a => option<React.element>): React.element => {
Belt.Option.flatMap(x, f)->Belt.Option.getWithDefault(React.null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment