I'm trying to make something like this work:


someData // Query[whatever...] /* summarizeInPrettyWay /* promptToRemoveCompoundExpression ;

should produce

(Please remove the semicolon and re-evaluate in order to see a summary of the data)

In words, I want to operate on some data (usually, in order to reduce it into a more manageable data set appropriate for some specific type of operation), prepare a summary of this reduced data set and allow the user of the Notebook to either see the summary or not (hence why I use a semicolon (;) at the end of the expression).

If the user decides not to remove the semicolon, when evaluating the cell (they evaluate a CompoundExpression) they will see a message informing them, that there is a summary of the data they just calculated, which they can review by removing the semicolon and re-evaluating the cell.

On the other hand, if the user decides to remove the semicolon (they evaluate a RightComposition) and evaluate, then the output is some summary description of the data without any message (prompting them to remove a semicolon, in order to see the summary).

The data are in the form of { <|key -> value, ...|>, ... }.

So far, I am failing.


This is the summary code:

funcs = {First, Last};
pretty = (Thread[{Length, Element} -> (MapAt[(Thread[funcs -> #]&) /* 
   Association, #, -1])] &) /* Association;
summary = (Through[{Length, Through[funcs[#]]&}[#]]&) /* pretty;

And here's a toy dataset:

toy = {

This is what I came up with:

msg = "Please remove the semicolon and re-evaluate to see a summary";
prompt /: CompoundExpression[__, prompt] := Print[msg]
prompt /: RightComposition[__, prompt] := Identity

And here are the ways it fails:

  1. toy // Query[Select[#z == "alpha" &]] /* summary /* Dataset /* prompt; doesn't print a message, as it should have.

  2. toy // Query[Select[#z == "alpha" &]] /* summary /* Dataset /* prompt evaluates to


when it should evaluate to

enter image description here

which is the expected output of toy // Query[Select[#z == "alpha" &]] /* summary /* Dataset (excluding the /* prompt)



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.