SafeCastOverDict.yqls 765 B

12345678910111213141516171819202122
  1. (
  2. (let config (DataSource 'config))
  3. (let res_sink (DataSink 'result))
  4. # Dict<Int32, String> -> Dict<Uint8, Utf8> (full)
  5. (let targetType (DictType (DataType 'Uint8) (DataType 'Utf8)))
  6. (let src (AsDict '((Int32 '1) (String 'one)) '((Int32 '2) (String 'two)) '((Int32 '3) (String 'three))))
  7. (let cast (SafeCast src targetType))
  8. (let world (Write! world res_sink (Key) cast '('('type))))
  9. # Dict<Int32, String> -> Dict<Int64, Utf8> (less)
  10. (let targetType (DictType (DataType 'Int64) (DataType 'Utf8)))
  11. (let src (AsDict '((Int32 '1) (String 'one)) '((Int32 '2) (String '"\xff\xfe")) '((Int32 '3) (String 'three))))
  12. (let cast (SafeCast src targetType))
  13. (let world (Write! world res_sink (Key) cast '('('type))))
  14. (let world (Commit! world res_sink))
  15. (return world)
  16. )