Header menu logo PhysicsSandbox

Helpers Module

General-purpose utility functions for error handling, timing, and thread control.

Functions and values

Function or value Description

ok arg1

Full Usage: ok arg1

Parameters:
Returns: 'a The contained value if Ok.

Unwraps an Ok value from a Result, throwing an exception on Error.

All PhysicsClient operations return Result<'a, string>. Use ok for scripting convenience; prefer pattern matching in production code.

arg0 : Result<'a, string>
Returns: 'a

The contained value if Ok.

Exception Thrown with the error message when the result is Error.
Example

 let s = connect "http://localhost:5180" |> ok   // throws on connection failure
 let count = clearAll session |> ok               // returns cleared body count
val s: obj
val count: obj

sleep arg1

Full Usage: sleep arg1

Parameters:
    arg0 : int

Pauses the current thread for the specified number of milliseconds.

arg0 : int

timed arg1 arg2

Full Usage: timed arg1 arg2

Parameters:
    arg0 : string
    arg1 : unit -> 'a

Returns: 'a The return value of f.

Executes a function, measures its wall-clock duration, and prints the elapsed time to the console.

Output format: [TIME] label: N ms. Useful for benchmarking command throughput.

arg0 : string
arg1 : unit -> 'a
Returns: 'a

The return value of f.

Example

 let bodies = timed "create 100 spheres" (fun () ->
     [ for i in 1..100 -> makeSphereCmd (nextId "sphere") (0.0, float i, 0.0) 0.3 1.0 ])
val bodies: obj
Multiple items
val float: value: 'T -> float (requires member op_Explicit)

--------------------
type float = System.Double

--------------------
type float<'Measure> = float

Type something to start searching.