Skip to content
Closed
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
4 changes: 3 additions & 1 deletion builtin/iterator.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ pub impl[X : Show] Show for Iter[X] with output(self, logger) {

///|
pub impl[X : ToJson] ToJson for Iter[X] with to_json(self) {
Json::array(self.map(x => x.to_json()).collect())
[
for x in self => x
]
}

///|
Expand Down
4 changes: 3 additions & 1 deletion deque/deque.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,9 @@ pub fn Deque::join(self : Deque[String], separator : StringView) -> String {
/// ```
///
pub impl[A : ToJson] ToJson for Deque[A] with to_json(self : Deque[A]) -> Json {
Json::array([ for x in self => x.to_json() ])
[
for x in self => x
]
}

///|
Expand Down
10 changes: 3 additions & 7 deletions hashset/hashset.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,9 @@ pub fn[K] HashSet::copy(self : HashSet[K]) -> HashSet[K] {
///|
/// ToJson implementation for hashset
pub impl[X : ToJson] ToJson for HashSet[X] with to_json(self) {
let res = Array::new(capacity=self.size)
for entry in self.entries {
if entry is Some({ key, .. }) {
res.push(key.to_json())
}
}
Json::array(res)
[
for key in self => key
]
}

///|
Expand Down
4 changes: 3 additions & 1 deletion immut/priority_queue/types.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ priv enum Node[A] {
pub impl[A : ToJson + Compare] ToJson for PriorityQueue[A] with to_json(
self : PriorityQueue[A],
) {
Json::array([ for item in self => item.to_json() ])
[
for item in self => item
]
}
4 changes: 3 additions & 1 deletion immut/sorted_set/immutable_set.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,9 @@ pub impl[A : Show] Show for SortedSet[A] with output(self, logger) {

///|
pub impl[A : ToJson] ToJson for SortedSet[A] with to_json(self) {
Json::array([ for a in self => a.to_json() ])
[
for a in self => a.to_json()
]
}

///|
Expand Down
4 changes: 3 additions & 1 deletion immut/vector/vector.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,9 @@ pub impl[A : Show] Show for Vector[A] with output(self, logger) {

///|
pub impl[A : ToJson] ToJson for Vector[A] with to_json(self) {
Json::array([ for value in self => value.to_json() ])
[
for value in self => value
]
}

///|
Expand Down
2 changes: 1 addition & 1 deletion immut/vector/vector_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test "to_array empty" {
///|
test "to_json" {
let v = @vector.from_iter((0).until(40))
let expected = Json::array(Array::makei(40, i => i.to_json()))
let expected : Json = [ for i in 0..<40 => i ]
@json.json_inspect(v, content=expected)
let empty : @vector.Vector[Int] = @vector.new()
@json.json_inspect(empty, content=[])
Expand Down
10 changes: 3 additions & 7 deletions list/list.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,9 @@ pub impl[A : Show] Show for List[A] with output(xs, logger) {
/// ToJson implementation for List.
/// Converts a list to a JSON array.
pub impl[A : ToJson] ToJson for List[A] with to_json(self) {
let capacity = self.length()
guard capacity != 0 else { return [] }
let jsons = Array::new(capacity~)
for a in self {
jsons.push(a.to_json())
}
Json::array(jsons)
[
for a in self => a
]
}

///|
Expand Down
2 changes: 1 addition & 1 deletion priority_queue/moon.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
"moonbitlang/core/debug",
"moonbitlang/core/quickcheck",
"moonbitlang/core/quickcheck/splitmix",
"moonbitlang/core/json",
}

import {
"moonbitlang/core/random",
"moonbitlang/core/cmp",
"moonbitlang/core/json",
} for "test"

options(
Expand Down
4 changes: 3 additions & 1 deletion priority_queue/priority_queue.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ pub fn[A : Compare] PriorityQueue::iter(self : PriorityQueue[A]) -> Iter[A] {

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

///|
Expand Down
8 changes: 3 additions & 5 deletions set/linked_hash_set.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,9 @@ pub fn[K : Hash + Eq] Set::intersection(

///|
pub impl[X : ToJson] ToJson for Set[X] with to_json(self) {
let res = Array::new(capacity=self.size)
for v in self {
res.push(v.to_json())
}
Json::array(res)
[
for v in self => v
]
}

///|
Expand Down
Loading