AlterToOverVariant.yqls 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. (
  2. (library "alterto.yql")
  3. (import alterto_module '"alterto.yql")
  4. (let config (DataSource 'config))
  5. ### Tuple
  6. (let srcType (VariantType (TupleType (DataType 'Int32) (DataType 'String))))
  7. (let targetType (VariantType (TupleType (DataType 'Uint8) (DataType 'Utf8))))
  8. (let failValue (Variant (Utf8 '"not converted") '1 targetType))
  9. # Variant<Tuple<Int32, String>> -> Variant<Tuple<Uint8, Utf8>>
  10. (let value (Variant (String 'one) '1 srcType))
  11. (let world (Apply (bind alterto_module 'doAlterTo) world value targetType failValue))
  12. # Variant<Tuple<Int32, String>> -> Variant<Tuple<Uint8, Utf8>> (fail)
  13. (let value (Variant (String '"garbage\xff") '1 srcType))
  14. (let world (Apply (bind alterto_module 'doAlterTo) world value targetType failValue))
  15. ### Struct
  16. (let srcType (VariantType (StructType '('a (DataType 'Int32)) '('b (DataType 'String)))))
  17. (let targetType (VariantType (StructType '('a (DataType 'Uint8)) '('b (DataType 'Utf8)))))
  18. (let failValue (Variant (Uint8 '123) 'a targetType))
  19. # Variant<Struct<Int32, String>> -> Variant<Struct<Uint8, Utf8>>
  20. (let value (Variant (Int32 '1) 'a srcType))
  21. (let world (Apply (bind alterto_module 'doAlterTo) world value targetType failValue))
  22. # Variant<Struct<Int32, String>> -> Variant<Struct<Uint8, Utf8>> (fail)
  23. (let value (Variant (Int32 '"-1") 'a srcType))
  24. (let world (Apply (bind alterto_module 'doAlterTo) world value targetType failValue))
  25. (return world)
  26. )