// compare hashset

///|
fn[T : Eq + Hash] hashset_eq(
  xs : @hashset.HashSet[T],
  ys : @hashset.HashSet[T],
) -> Bool {
  if xs.length() != ys.length() {
    return false
  }
  for x in xs {
    if !ys.contains(x) {
      return false
    }
  }
  true
}

///|
pub fn raf_loop(f : (Float) -> Unit raise RespoCommonError) -> Unit {
  let win = @dom_ffi.window()
  let cb = Ref(fn(_t : Float) -> Unit {
    // placeholder

  })
  cb.val = fn(t : Float) -> Unit {
    f(t) catch {
      e => @dom_ffi.error_log(e.to_string())
    }
    let _ = win.request_animation_frame(cb.val)
  }
  let _ = win.request_animation_frame(cb.val)
}

///|
/// convert a list of strings to a single string with spaces between them,
/// mainly used for concatenating class names
pub fn str_spaced(wrap_parens? : Bool = false, s : Array[&Show]) -> String {
  let mut ret = ""
  for idx, piece in s.iter2() {
    if idx > 0 {
      ret = ret + " "
    }
    ret = ret + piece.to_string()
  }
  if wrap_parens {
    ret = "(" + ret + ")"
  }
  ret
}