Skip to content

Commit

Permalink
Add singleton function to immut/list
Browse files Browse the repository at this point in the history
  • Loading branch information
bob.hongbo.zhang committed Oct 20, 2024
1 parent 0930bce commit cb51303
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions immut/list/list.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions immut/list/list.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 2 additions & 1 deletion immut/list/list_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit cb51303

Please sign in to comment.