8000 fmt docstring by bobzhang · Pull Request #2348 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fmt docstring #2348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions double/to_uint_wasm.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
/// Example:
///
/// ```moonbit
/// inspect(42.0.to_uint(), content="42")
/// inspect((-42.5).to_uint(), content="0")
/// inspect((0.0 / 0.0).to_uint(), content="0") // NaN
/// inspect((1.0 / 0.0).to_uint(), content="4294967295") // Infinity
/// inspect((-1.0 / 0.0).to_uint(), content="0") // -Infinity
/// inspect(42.0.to_uint(), content="42")
/// inspect((-42.5).to_uint(), content="0")
/// inspect((0.0 / 0.0).to_uint(), content="0") // NaN
/// inspect((1.0 / 0.0).to_uint(), content="4294967295") // Infinity
/// inspect((-1.0 / 0.0).to_uint(), content="0") // -Infinity
/// ```
pub fn to_uint(self : Double) -> UInt = "%f64.to_u32_saturate"
24 changes: 12 additions & 12 deletions float/float.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
/// Example:
///
/// ```moonbit
/// inspect(@float.not_a_number.is_nan(), content="true")
/// inspect(@float.not_a_number + 1.0, content="NaN")
/// inspect(@float.not_a_number.is_nan(), content="true")
/// inspect(@float.not_a_number + 1.0, content="NaN")
/// ```
pub let not_a_number : Float = (0x7FC00000).reinterpret_as_float()

Expand All @@ -36,8 +36,8 @@ pub let not_a_number : Float = (0x7FC00000).reinterpret_as_float()
/// Example:
///
/// ```moonbit
/// inspect(@float.infinity.is_pos_inf(), content="true")
/// inspect(@float.infinity > 1.0, content="true")
/// inspect(@float.infinity.is_pos_inf(), content="true")
/// inspect(@float.infinity > 1.0, content="true")
/// ```
pub let infinity : Float = (0x7F800000).reinterpret_as_float()

Expand All @@ -51,8 +51,8 @@ pub let infinity : Float = (0x7F800000).reinterpret_as_float()
/// Example:
///
/// ```moonbit
/// inspect(@float.neg_infinity.is_neg_inf(), content="true")
/// inspect(@float.neg_infinity < (-1.0 : Float), content="true")
/// inspect(@float.neg_infinity.is_neg_inf(), content="true")
/// inspect(@float.neg_infinity < (-1.0 : Float), content="true")
/// ```
pub let neg_infinity : Float = (0xFF800000).reinterpret_as_float()

Expand All @@ -63,8 +63,8 @@ pub let neg_infinity : Float = (0xFF800000).reinterpret_as_float()
/// Example:
///
/// ```moonbit
/// inspect(@float.max_value < @float.infinity, content="true")
/// inspect(@float.max_value > 0.0, content="true")
/// inspect(@float.max_value < @float.infinity, content="true")
/// inspect(@float.max_value > 0.0, content="true")
/// ```
pub let max_value : Float = (0x7F7FFFFF).reinterpret_as_float()

Expand All @@ -74,8 +74,8 @@ pub let max_value : Float = (0x7F7FFFFF).reinterpret_as_float()
/// Example:
///
/// ```moonbit
/// inspect(@float.min_value < -1.0, content="true")
/// inspect(@float.min_value > @float.neg_infinity, content="true")
/// inspect(@float.min_value < -1.0, content="true")
/// inspect(@float.min_value > @float.neg_infinity, content="true")
/// ```
pub let min_value : Float = (0xFF7FFFFF).reinterpret_as_float()

Expand All @@ -86,8 +86,8 @@ pub let min_value : Float = (0xFF7FFFFF).reinterpret_as_float()
/// Example:
///
/// ```moonbit
/// inspect(@float.min_positive > 0.0, content="true")
/// inspect(@float.min_positive < 1.2e-38, content="true")
/// inspect(@float.min_positive > 0.0, content="true")
/// inspect(@float.min_positive < 1.2e-38, content="true")
/// ```
pub let min_positive : Float = (0x00800000).reinterpret_as_float()

Expand Down
14 changes: 8 additions & 6 deletions json/README.mbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ test "parse and validate jsons" {
assert_true(@json.valid("false"))

// Parse JSON string into Json value
let json = try @json.parse("{\"key\": 42}") catch {
let json = @json.parse("{\"key\": 42}") catch {
(_ : ParseError) => panic()
// _ => panic() // redundant, the type checker won't refine further
}

// Pretty print with indentation
inspect(
json.stringify(indent=2),
content=
#|{
#| "key": 42
#|}
,
content={
let output =
#|{
#| "key": 42
#|}
output
},
)
}
```
Expand Down
6 changes: 4 additions & 2 deletions priority_queue/README.mbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ You can use `new()` or `of()` to create a priority queue.

```moonbit
test {
let _queue1 : @priority_queue.T[Int] = @priority_queue.new()
let _queue2 = @priority_queue.of([1, 2, 3])
let queue1 : @priority_queue.T[Int] = @priority_queue.new()
let queue2 = @priority_queue.of([1, 2, 3])
@json.inspect(queue1, content=[])
@json.inspect(queue2, content=[3,2,1])
}
```

Expand Down
3 changes: 2 additions & 1 deletion priority_queue/moon.pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"moonbitlang/core/builtin",
"moonbitlang/core/array",
"moonbitlang/core/quickcheck",
"moonbitlang/core/quickcheck/splitmix"
"moonbitlang/core/quickcheck/splitmix",
"moonbitlang/core/json"
],
"test-import": ["moonbitlang/core/random"],
"targets": {
Expand Down
41 changes: 25 additions & 16 deletions priority_queue/priority_queue.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ fn[A] copy_node(x : Node[A]) -> Node[A] {
///
/// # Example
/// ```mbt
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// let queue2 = queue.copy()
/// assert_eq(queue2.length(), 4)
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// let queue2 = queue.copy()
/// inspect(queue2.length(), content="4")
/// ```
pub fn[A] copy(self : T[A]) -> T[A] {
let new_que : T[A] = { len: self.len, top: copy_node(self.top) }
Expand Down Expand Up @@ -104,6 +104,15 @@ pub fn[A : Compare] iter(self : T[A]) -> Iter[A] {
})
}

///|
pub impl[A : ToJson + Compare] ToJson for T[A] with to_json(self) {
let arr = []
for x in self {
arr.push(x.to_json())
}
Json::array(arr)
}

///|
pub fn[K : Compare] from_iter(iter : Iter[K]) -> T[K] {
let s = new()
Expand Down Expand Up @@ -152,9 +161,9 @@ pub fn[A] length(self : T[A]) -> Int {
///
/// # Example
/// ```mbt
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// queue.unsafe_pop()
/// assert_eq(queue.length(), 3)
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// queue.unsafe_pop()
/// inspect(queue.length(), content="3")
/// ```
#internal(unsafe, "Panic if the queue is empty.")
pub fn[A : Compare] unsafe_pop(self : T[A]) -> Unit {
Expand All @@ -170,10 +179,10 @@ pub fn[A : Compare] unsafe_pop(self : T[A]) -> Unit {
///
/// # Example
/// ```mbt
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// let first = queue.pop() // Some(4)
/// assert_eq(first, Some(4))
/// assert_eq(queue.length(), 3)
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// let first = queue.pop() // Some(4)
/// inspect(first, content="Some(4)")
/// inspect(queue.length(), content="3")
/// ```
pub fn[A : Compare] pop(self : T[A]) -> A? {
let result = self.peek()
Expand All @@ -192,9 +201,9 @@ pub fn[A : Compare] pop(self : T[A]) -> A? {
///
/// # Example
/// ```mbt
/// let queue = @priority_queue.new()
/// queue.push(1)
/// assert_eq(queue.length(), 1)
/// let queue = @priority_queue.new()
/// queue.push(1)
/// assert_eq(queue.length(), 1)
/// ```
pub fn[A : Compare] push(self : T[A], value : A) -> Unit {
self.top = meld(self.top, Cons(content=value, sibling=Nil, child=Nil))
Expand Down Expand Up @@ -222,9 +231,9 @@ pub fn[A] peek(self : T[A]) -> A? {
///
/// # Example
/// ```mbt
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// queue.clear()
/// assert_eq(queue.length(), 0)
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// queue.clear()
/// assert_eq(queue.length(), 0)
/// ```
pub fn[A] clear(self : T[A]) -> Unit {
self.top = Nil
Expand Down
1 change: 1 addition & 0 deletions priority_queue/priority_queue.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn[A : Compare] T::to_array(Self[A]) -> Array[A]
fn[A : Compare] T::unsafe_pop(Self[A]) -> Unit
impl[K] Default for T[K]
impl[A : Show + Compare] Show for T[A]
impl[A : ToJson + Compare] ToJson for T[A]
impl[X : @quickcheck.Arbitrary + Compare] @quickcheck.Arbitrary for T[X]

// Type aliases
Expand Down
0