diff --git a/immut/list/list.mbt b/immut/list/list.mbt index cfb26887..4b91d46d 100644 --- a/immut/list/list.mbt +++ b/immut/list/list.mbt @@ -1025,3 +1025,7 @@ pub impl[X : @quickcheck.Arbitrary] @quickcheck.Arbitrary for T[X] with arbitrar ) { @quickcheck.Arbitrary::arbitrary(size, rs) |> from_array } + +pub fn singleton[A](x : A) -> T[A] { + Cons(x, Nil) +} diff --git a/immut/list/list.mbti b/immut/list/list.mbti index b43784a4..e6885301 100644 --- a/immut/list/list.mbti +++ b/immut/list/list.mbti @@ -6,6 +6,8 @@ alias @moonbitlang/core/quickcheck as @quickcheck // Values fn repeat[A](Int, A) -> T[A] +fn singleton[A](A) -> T[A] + fn unfold[A, S]((S) -> (A, S)?, ~init : S) -> T[A] fn unzip[A, B](T[(A, B)]) -> (T[A], T[B]) diff --git a/immut/list/list_test.mbt b/immut/list/list_test.mbt index bfee5f02..74123179 100644 --- a/immut/list/list_test.mbt +++ b/immut/list/list_test.mbt @@ -21,7 +21,8 @@ test "from_array" { test "length" { let ls = @list.of([1, 2, 3, 4, 5]) - inspect!(ls.length(), content="5") + @json.inspect!(ls.length(), content=5) + @json.inspect!(@list.singleton(11), content=[11]) } test "iter" {