Skip to content

Commit

Permalink
Merge pull request #298 from moonbitlang/hongbo/tuple_show_more
Browse files Browse the repository at this point in the history
support show for tuple whose elements are up to 7
  • Loading branch information
bobzhang authored Apr 21, 2024
2 parents b53267f + 13d88e9 commit 93c1ddd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tuple/tuple.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ fn Tuple::debug_write[X1 : @moonbitlang/core/builtin.Debug, X2 : @moonbitlang/co
fn Tuple::op_equal[T0 : @moonbitlang/core/builtin.Eq, T1 : @moonbitlang/core/builtin.Eq, T2 : @moonbitlang/core/builtin.Eq, T3 : @moonbitlang/core/builtin.Eq, T4 : @moonbitlang/core/builtin.Eq](Tuple[T0, T1, T2, T3, T4], Tuple[T0, T1, T2, T3, T4]) -> Bool
fn Tuple::to_string[A : @moonbitlang/core/builtin.Show, B : @moonbitlang/core/builtin.Show, C : @moonbitlang/core/builtin.Show, D : @moonbitlang/core/builtin.Show, E : @moonbitlang/core/builtin.Show](Tuple[A, B, C, D, E]) -> String
fn Tuple::op_equal[T0 : @moonbitlang/core/builtin.Eq, T1 : @moonbitlang/core/builtin.Eq, T2 : @moonbitlang/core/builtin.Eq, T3 : @moonbitlang/core/builtin.Eq, T4 : @moonbitlang/core/builtin.Eq, T5 : @moonbitlang/core/builtin.Eq](Tuple[T0, T1, T2, T3, T4, T5], Tuple[T0, T1, T2, T3, T4, T5]) -> Bool
fn Tuple::to_string[A : @moonbitlang/core/builtin.Show, B : @moonbitlang/core/builtin.Show, C : @moonbitlang/core/builtin.Show, D : @moonbitlang/core/builtin.Show, E : @moonbitlang/core/builtin.Show, F : @moonbitlang/core/builtin.Show](Tuple[A, B, C, D, E, F]) -> String
fn Tuple::op_equal[T0 : @moonbitlang/core/builtin.Eq, T1 : @moonbitlang/core/builtin.Eq, T2 : @moonbitlang/core/builtin.Eq, T3 : @moonbitlang/core/builtin.Eq, T4 : @moonbitlang/core/builtin.Eq, T5 : @moonbitlang/core/builtin.Eq, T6 : @moonbitlang/core/builtin.Eq](Tuple[T0, T1, T2, T3, T4, T5, T6], Tuple[T0, T1, T2, T3, T4, T5, T6]) -> Bool
fn Tuple::to_string[A : @moonbitlang/core/builtin.Show, B : @moonbitlang/core/builtin.Show, C : @moonbitlang/core/builtin.Show, D : @moonbitlang/core/builtin.Show, E : @moonbitlang/core/builtin.Show, F : @moonbitlang/core/builtin.Show, G : @moonbitlang/core/builtin.Show](Tuple[A, B, C, D, E, F, G]) -> String
fn Tuple::op_equal[T0 : @moonbitlang/core/builtin.Eq, T1 : @moonbitlang/core/builtin.Eq, T2 : @moonbitlang/core/builtin.Eq, T3 : @moonbitlang/core/builtin.Eq, T4 : @moonbitlang/core/builtin.Eq, T5 : @moonbitlang/core/builtin.Eq, T6 : @moonbitlang/core/builtin.Eq, T7 : @moonbitlang/core/builtin.Eq](Tuple[T0, T1, T2, T3, T4, T5, T6, T7], Tuple[T0, T1, T2, T3, T4, T5, T6, T7]) -> Bool
fn Tuple::op_equal[T0 : @moonbitlang/core/builtin.Eq, T1 : @moonbitlang/core/builtin.Eq, T2 : @moonbitlang/core/builtin.Eq, T3 : @moonbitlang/core/builtin.Eq, T4 : @moonbitlang/core/builtin.Eq, T5 : @moonbitlang/core/builtin.Eq, T6 : @moonbitlang/core/builtin.Eq, T7 : @moonbitlang/core/builtin.Eq, T8 : @moonbitlang/core/builtin.Eq](Tuple[T0, T1, T2, T3, T4, T5, T6, T7, T8], Tuple[T0, T1, T2, T3, T4, T5, T6, T7, T8]) -> Bool
fn Tuple::op_equal[T0 : @moonbitlang/core/builtin.Eq, T1 : @moonbitlang/core/builtin.Eq, T2 : @moonbitlang/core/builtin.Eq, T3 : @moonbitlang/core/builtin.Eq, T4 : @moonbitlang/core/builtin.Eq, T5 : @moonbitlang/core/builtin.Eq, T6 : @moonbitlang/core/builtin.Eq, T7 : @moonbitlang/core/builtin.Eq, T8 : @moonbitlang/core/builtin.Eq, T9 : @moonbitlang/core/builtin.Eq](Tuple[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9], Tuple[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]) -> Bool
Expand Down
16 changes: 16 additions & 0 deletions tuple/tuple_show.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ pub fn to_string[A : Show, B : Show, C : Show, D : Show, E : Show](
", " + self.3.to_string() + ", " + self.4.to_string() + ")"
}

pub fn to_string[A : Show, B : Show, C : Show, D : Show, E : Show, F : Show](
self : (A, B, C, D, E,F)
) -> String {
let (a,b,c,d,e,f) = self
"(\(a), \(b), \(c), \(d), \(e), \(f))"
}

pub fn to_string[A : Show, B : Show, C : Show, D : Show, E : Show, F : Show, G: Show](
self : (A, B, C, D, E, F, G)
) -> String {
let (a,b,c,d,e,f,g) = self
"(\(a), \(b), \(c), \(d), \(e), \(f), \(g))"
}

test "to_string" {
let tuple2 = (1, 2)
let tuple3 = ("a", "b", "c")
Expand All @@ -44,4 +58,6 @@ test "to_string" {
inspect(tuple3, content="(a, b, c)")?
inspect(tuple4, content="(1, 2, 3, hello)")?
inspect(tuple5, content="(List::[1], 2, 3, [4], 5)")?
inspect((1,2,3,4,5,6), ~content="(1, 2, 3, 4, 5, 6)")?
inspect((1,2,3,4,5,6,7), ~content="(1, 2, 3, 4, 5, 6, 7)")?
}

0 comments on commit 93c1ddd

Please sign in to comment.