Skip to content

Commit

Permalink
!106 until for case-list in (liii scala)
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Jan 11, 2025
1 parent 80648c5 commit 3d3b1dd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions goldfish/liii/scala.scm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
(case-list (list))
(case-list (iota (+ (- n data) 1) data))))

(typed-define (%until (n integer?))
(if (<= n data)
(case-list (list))
(case-list (iota (+ (- n data)) data))))

)

(define-case-class case-string ((data string?))
Expand Down
24 changes: 24 additions & 0 deletions liii_scala.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,30 @@
\;
</goldfish-chunk>

<paragraph|case-integer%until>

<\goldfish-chunk|goldfish/liii/scala.scm|true|false>
(typed-define (%until (n integer?))

\ \ (if (\<less\>= n data)

\ \ \ \ \ \ (case-list (list))

\ \ \ \ \ \ (case-list (iota (+ (- n data)) data))))

\;
</goldfish-chunk>

<\goldfish-chunk|tests/goldfish/liii/scala-test.scm|true|true>
(check (((box 1) :until 3) :collect) =\<gtr\> (list 1 2))

(check (((box 1) :until 2) :collect) =\<gtr\> (list 1))

(check (((box 2) :until 2) :collect) =\<gtr\> (list ))

\;
</goldfish-chunk>

<\goldfish-chunk|goldfish/liii/scala.scm|true|true>
)

Expand Down
4 changes: 4 additions & 0 deletions tests/goldfish/liii/scala-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
(check (((box 1) :to 1) :collect) => (list 1))
(check (((box 2) :to 1) :collect) => (list ))

(check (((box 1) :until 3) :collect) => (list 1 2))
(check (((box 1) :until 2) :collect) => (list 1))
(check (((box 2) :until 2) :collect) => (list ))

(check ((case-string "abc") :map char-upcase :unbox) => "ABC")

(check-true ((case-string "") :empty?))
Expand Down

0 comments on commit 3d3b1dd

Please sign in to comment.