validator.km 826 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # { "data": {"name":"Range", "version":"latest"} }
  2. type Range protected {
  3. a: Integer,
  4. b: Integer
  5. };
  6. function @validate: &(Range) => Bool
  7. & {a, b} => (a <= b);
  8. const Data1: String := 'KumaChan Data
  9. {} ..Range latest
  10. a integer
  11. 1
  12. b integer
  13. 2';
  14. const Data2: String := 'KumaChan Data
  15. {} ..Range latest
  16. a integer
  17. 3
  18. b integer
  19. 2';
  20. function describe-deserialized:
  21. &(String) => String
  22. &(data) =>
  23. switch { @deserialize { encode data } }.[Result[Range,Error]]:
  24. case Success range:
  25. let { a, b } := range,
  26. { "(?, ?)" (a.{String}, b.{String}) },
  27. case Failure err:
  28. err.{String},
  29. end;
  30. do
  31. [{ describe-deserialized Data1 }, { describe-deserialized Data2 }]
  32. . { join \n }
  33. . { os::println }
  34. . { crash-on-error };