Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1819

Accessing array items by index, brackets return option?

$
0
0

As others said, having Core open causes this behavior. But if you really want unsafe access, you can write an Array module that has its own get function that returns 'a instead of option<'a>.

// with Core open

let xs = [1, 2, 3]

let m = xs[1] 
//  ^ option<int>

module Array = {
  @get_index external get: (array<'a>, int) => 'a = ""
}

let n = xs[1]
//  ^ int

Playground URL


Viewing all articles
Browse latest Browse all 1819

Trending Articles