Skip to content

Commit 9755b22

Browse files
committed
std: Add std/flip
1 parent 8f8d7af commit 9755b22

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

core/src/ys/std.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@
302302
(intern 'ys.std 'T to-type)
303303
(intern 'ys.std 'V to-vec)
304304

305+
(intern 'ys.std 'V+ vector)
306+
305307

306308
;;------------------------------------------------------------------------------
307309
;; Math functions
@@ -516,6 +518,25 @@
516518
(defmacro when+ [test & body]
517519
(list 'when-let ['_ test] (cons 'do body)))
518520

521+
522+
;;------------------------------------------------------------------------------
523+
;; Function functions
524+
;;------------------------------------------------------------------------------
525+
526+
(defn flip [f]
527+
(fn
528+
([] (f))
529+
([a] (f a))
530+
([a b] (f b a))
531+
([a b c] (f c b a))
532+
([a b c d] (f d c b a))
533+
([a b c d & rest]
534+
(->> rest
535+
(concat [a b c d])
536+
clojure.core/reverse
537+
(apply f)))))
538+
539+
519540
;;------------------------------------------------------------------------------
520541
;; String functions
521542
;;------------------------------------------------------------------------------

ys/test/std.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ test::
219219
want: 42
220220
221221
222+
#-------------------------------------------------------------------------------
223+
- note: "Function functions"
224+
225+
- code: |
226+
bus =: sub:flip
227+
bus: 2 44
228+
want: 42
229+
230+
222231
#-------------------------------------------------------------------------------
223232
- note: "String functions"
224233

0 commit comments

Comments
 (0)