August 28, 2018
Just Juxt #14: Juxtaposition (4clojure #59)
Take a set of functions and return a new function that takes a variable number of arguments and returns a sequence containing the result of applying each function left-to-right to the argument list.
...but without using juxt
!
Here we are turning (just juxt) on its head, and faced with the task of implementing it ourselves!
(ns live.test
(:require [cljs.test :refer-macros [deftest is testing run-tests]]))
(defn juxtapose [& f]
)
(deftest test-59
(is (= [21 6 1] ((juxtapose + max min) 2 3 5 1 6 4)))
(is (= ["HELLO" 5] ((juxtapose #(.toUpperCase %) count) "hello")))
(is (= [2 6 4] ((juxtapose :a :c :b) {:a 2, :b 4, :c 6, :d 8 :e 10}))))
(run-tests)
Here is a simple solution:
(defn juxtapose [& f]
(fn [& a]
(map #(apply % a) f)))
(run-tests)