Skip to content

Commit

Permalink
std: Add std/flip
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Jan 29, 2025
1 parent 8f8d7af commit 9755b22
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/ys/std.clj
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@
(intern 'ys.std 'T to-type)
(intern 'ys.std 'V to-vec)

(intern 'ys.std 'V+ vector)


;;------------------------------------------------------------------------------
;; Math functions
Expand Down Expand Up @@ -516,6 +518,25 @@
(defmacro when+ [test & body]
(list 'when-let ['_ test] (cons 'do body)))


;;------------------------------------------------------------------------------
;; Function functions
;;------------------------------------------------------------------------------

(defn flip [f]
(fn
([] (f))
([a] (f a))
([a b] (f b a))
([a b c] (f c b a))
([a b c d] (f d c b a))
([a b c d & rest]
(->> rest
(concat [a b c d])
clojure.core/reverse
(apply f)))))


;;------------------------------------------------------------------------------
;; String functions
;;------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions ys/test/std.t
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ test::
want: 42
#-------------------------------------------------------------------------------
- note: "Function functions"
- code: |
bus =: sub:flip
bus: 2 44
want: 42
#-------------------------------------------------------------------------------
- note: "String functions"
Expand Down

0 comments on commit 9755b22

Please sign in to comment.