rescript-association / reasonml.org

Deprecated in favor of rescript-lang.org
MIT License
125 stars 34 forks source link

Simpler Belt Examples (like Belt.Set) #241

Open peterpme opened 3 years ago

peterpme commented 3 years ago

I was trying to understand how to use Belt.set and the example I see is.

Even for somebody whose used a bit of Reason, this takes a bit to grok 😅

module PairComparator =
  Belt.Id.MakeComparable({
    type t = (int, int)
    let cmp = ((a0, a1), (b0, b1)) =>
      switch (Pervasives.compare(a0, b0)) {
      | 0 => Pervasives.compare(a1, b1)
      | c => c
      }
  })

let mySet = Belt.Set.make(~id=module(PairComparator))
let mySet2 = Belt.Set.add(mySet, (1, 2))

In this specific example, I don't have an alternative but just wanted to bring this to attention. Thanks!