This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Belt Module
Overview
Belt
submodules
  • Array
  • Float
  • HashMap
    • String
    • Int
    HashSet
    • t
      t
    • t
      id
    • v
      make
    • v
      clear
    • v
      isEmpty
    • v
      add
    • v
      copy
    • v
      has
    • v
      remove
    • v
      forEachU
    • v
      forEach
    • v
      reduceU
    • v
      reduce
    • v
      size
    • v
      logStats
    • v
      toArray
    • v
      fromArray
    • v
      mergeMany
    • v
      getBucketHistogram
    • String
    • Int
    Id
    • MakeHashable
    • MakeHashableU
    • MakeComparable
    • MakeComparableU
  • Int
  • List
  • Map
    • Dict
    • String
    • Int
    MutableMap
    • String
    • Int
  • MutableQueue
  • MutableSet
    • String
    • Int
  • MutableStack
  • Option
  • Range
  • Result
  • Set
    • Dict
    • String
    • Int
    SortArray
    • String
    • Int
    API / Belt / Hashset

    HashSet

    A mutable Hash set which allows customized hash behavior.

    All data are parameterized by not its only type but also a unique identity in the time of initialization, so that two HashSets of ints initialized with different hash functions will have different type.

    Examples

    RESCRIPT
    module I0 = unpack( Belt.Id.hashableU( ~hash=(. a: int) => land(a, 65535), ~eq=(. a, b) => a == b, ) ) let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) module I1 = unpack( Belt.Id.hashableU( ~hash=(. a: int) => land(a, 255), ~eq=(. a, b) => a == b, ) ) let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) Belt.HashSet.add(s1, 0) Belt.HashSet.add(s1, 1)

    The invariant must be held: for two elements who are equal, their hashed value should be the same.

    Here the compiler would infer s0 and s1 having different type so that it would not mix.

    Examples

    RESCRIPT
    let s0: Belt.HashSet.t<int, I0.identity> let s1: Belt.HashSet.t<int, I1.identity>

    We can add elements to the collection (see last two lines in the example above). Since this is an mutable data structure, s1 will contain two pairs.

    t

    RESCRIPT
    type t<'a, 'id>

    id

    RESCRIPT
    type id<'a, 'id> = Belt_Id.hashable<'a, 'id>

    The type of hash tables from type 'a to type 'b.

    make

    RESCRIPT
    let make: (~hintSize: int, ~id: id<'a, 'id>) => t<'a, 'id>

    clear

    RESCRIPT
    let clear: t<'a, 'id> => unit

    isEmpty

    RESCRIPT
    let isEmpty: t<'a, 'b> => bool

    add

    RESCRIPT
    let add: (t<'a, 'id>, 'a) => unit

    copy

    RESCRIPT
    let copy: t<'a, 'id> => t<'a, 'id>

    has

    RESCRIPT
    let has: (t<'a, 'id>, 'a) => bool

    remove

    RESCRIPT
    let remove: (t<'a, 'id>, 'a) => unit

    forEachU

    RESCRIPT
    let forEachU: (t<'a, 'id>, 'a => unit) => unit

    forEach

    RESCRIPT
    let forEach: (t<'a, 'id>, 'a => unit) => unit

    Order unspecified.

    reduceU

    RESCRIPT
    let reduceU: (t<'a, 'id>, 'c, ('c, 'a) => 'c) => 'c

    reduce

    RESCRIPT
    let reduce: (t<'a, 'id>, 'c, ('c, 'a) => 'c) => 'c

    Order unspecified.

    size

    RESCRIPT
    let size: t<'a, 'id> => int

    logStats

    RESCRIPT
    let logStats: t<'a, 'b> => unit

    toArray

    RESCRIPT
    let toArray: t<'a, 'id> => array<'a>

    fromArray

    RESCRIPT
    let fromArray: (array<'a>, ~id: id<'a, 'id>) => t<'a, 'id>

    mergeMany

    RESCRIPT
    let mergeMany: (t<'a, 'id>, array<'a>) => unit

    getBucketHistogram

    RESCRIPT
    let getBucketHistogram: t<'a, 'b> => array<int>
    Types and values
    • t
      t
    • t
      id
    • v
      make
    • v
      clear
    • v
      isEmpty
    • v
      add
    • v
      copy
    • v
      has
    • v
      remove
    • v
      forEachU
    • v
      forEach
    • v
      reduceU
    • v
      reduce
    • v
      size
    • v
      logStats
    • v
      toArray
    • v
      fromArray
    • v
      mergeMany
    • v
      getBucketHistogram

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on