reducecombine / fridge

Ideas for awesomer Clojure development
0 stars 0 forks source link

->/->> drop-in replacements that detailedly report errors #2

Open vemv opened 5 years ago

vemv commented 5 years ago

Create a ->/->>/some->/some->> replacement such that if any member of the chain fails, all previous members' (inclusive) arguments and return values are printlned.

This would greatly improve the debuggability of Clojure programs, and foster usage of threading macros, which are superior to call chains for a number of reasons.

Example:

The (-> x f1 (f2 some-arg) f3) chain failed at f2.

f1 execution:

  Input:

    {:a 2}

  Output:

    {:a 3000}

f2 execution:

  Input:

    {:a 3000},
    ::some-argument

  Exception:

   FooBarException

The implementation should observe clojure.core/*assert*:

Considerations

vemv commented 5 years ago

Some prior art exists, but personally I don't find those -> replacements as elegant.

This one would be truly drop-in and zero-cost, with nothing new for users to learn.