Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active October 10, 2022 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PEZ/8bdf1dba5225cd748e4d53545f7f68f7 to your computer and use it in GitHub Desktop.
Save PEZ/8bdf1dba5225cd748e4d53545f7f68f7 to your computer and use it in GitHub Desktop.
Decurry – Rich 4Clojure Problem 158 – See: https://github.com/PEZ/rich4clojure
(ns rich4clojure.medium.problem-158
(:require [hyperfiddle.rcf :refer [tests]]))
;; = Decurry =
;; By 4Clojure user: amcnamara
;; Difficulty: Medium
;; Tags: [partial-functions]
;;
;; Write a function that accepts a curried function of
;; unknown arity n. Return an equivalent function of n
;; arguments.
;;
;; You may wish to read this .
(def __ :tests-will-fail)
(comment
)
(tests
10 := ((__ (fn [a]
(fn [b]
(fn [c]
(fn [d]
(+ a b c d))))))
1 2 3 4)
24 := ((__ (fn [a]
(fn [b]
(fn [c]
(fn [d]
(* a b c d))))))
1 2 3 4)
25 := ((__ (fn [a]
(fn [b]
(* a b))))
5 5))
;; To participate, fork:
;; https://github.com/PEZ/rich4clojure
;; Post your solution below, please!
@StanTheBear
Copy link

(def __ "take curried fn fx of n args; make equiv fn fx args 1..n"
  (fn [fx]
    (fn [& args] ; acc in fx the reduce of n args 
      (reduce #(%1 %2) fx args))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment