#!/usr/bin/env nush -f ScriptingBridge
(set iTunes (SBApplication applicationWithBundleIdentifier: "com.apple.iTunes"))
; I recently started playing around with Nu and found myself writing an expression along the lines of this:
((((iTunes currentPlaylist) tracks) list) map: (do (t) "#{(t artist)} - #{(t name)}"))
; Yes, it is too deep and could be broken into two steps but the Clojurian in me wanted to pipeline the method calls, so he wrote a macro:
(macro |> (first second *rest)
(if (== *rest (list))
(then (if (list? second)
(then `(,first ,@second))
(else `(,first ,second))))
(else `(|> (|> ,first ,second) ,@*rest))))
; And used it:
(|> iTunes
currentPlaylist
tracks
list
(map: (do (t) "#{(t artist)} - #{(t name)}")))
; And was quite happy!
; But then wondered:
;
; 1. Is there something like this built-in in Nu that I have missed?
;
; 2. Is this something somebody else would enjoy to use?
;
; 3. macrox -- which I used when writing this macro -- only expands a single step. Is there something in Nu that expands fully?
(macrox (|> iTunes currentPlaylist tracks ...))
; => (|> (|> iTunes currentPlaylist) tracks ...)
(macrox (|> (|> iTunes currentPlaylist) tracks ...))
; => (|> (|> (|> iTunes currentPlaylist) tracks) ...)
; ...