Guest User

Untitled

a guest
Nov 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <|"x"->{... big list ...},....|>
  2.  
  3. x:[xMinValue,xMaxValue] (where xMinValue=Min[{..Big List...}]...)
  4.  
  5. Format[f[x_?ListQ]] :=
  6. "f[x], x:[" <> ToString[Min[x]] <> ", " <> ToString[Max[x]] <> "]"
  7.  
  8. In[2]= f[Range[20]]]
  9.  
  10. Out[2]= f[x], x:[1, 20]
  11.  
  12. In[3]= Format[<|"x"->x_?ListQ|>] :=
  13. "x:[" <> ToString[Min[x]] <> ", " <> ToString[Max[x]] <> "]"
  14.  
  15. Unprotect[Association];
  16. format[x_List] := "<< Very long list that we do not want to see, honestly. >>";
  17. format[x_] := x;
  18. Association /: Format[a_Association] :=
  19. Row[{"[LeftAssociation]",
  20. Sequence @@
  21. Riffle[Rule @@@ Transpose[{Keys[a], format /@ Values[a]}], ", "],
  22. "[RightAssociation]"}]
  23. Protect[Association];
  24.  
  25. Association["Bli" -> 1, "Bla" -> Association["Blabla" -> {2, 3}], "Blubb" -> {4, 5}]
  26.  
  27. MyAssocationQ[assoc_] := MatchQ[assoc, <|"x" -> _?ListQ|>]
  28.  
  29. MyAssocationQ[<|"x" -> {-5, 2, 9}|>]
  30.  
  31. MyAssocationQ[2017]
  32. MyAssocationQ[<|"x" -> {-5, 2, 9},"y"->1|>]
  33.  
  34. Unprotect[Association];
  35.  
  36. Association /: Format[assoc_Association /; MyAssocationQ[assoc]] :=
  37. "x:[" <> ToString[Min[assoc["x"]]] <> ", " <>
  38. ToString[Max[assoc["x"]]] <> "]";
  39.  
  40. Protect[Association];
  41.  
  42. In[]= <|"x" -> {-5, 2, 9}|>
  43.  
  44. In[]= <|"x" -> {-5, 2, 9}, "y" -> 5|>
Add Comment
Please, Sign In to add comment