array_methods.ion 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. echo '# ANCHOR: lines'
  2. echo @lines($unescape("firstline\nsecondline"))
  3. for line in @lines($unescape("third\nfourth\nfifth"))
  4. echo $line
  5. end
  6. echo '# ANCHOR_END: lines'
  7. echo '# ANCHOR: split'
  8. echo @split("onetwoone" "two")
  9. for data in @split("person, age, some data" ", ")
  10. echo $data
  11. end
  12. for data in @split("person age data")
  13. echo $data
  14. end
  15. echo '# ANCHOR_END: split'
  16. echo '# ANCHOR: split_at'
  17. echo @split_at("onetwoone" "3")
  18. echo @split_at("FOOBAR" "3")
  19. #echo @split_at("FOOBAR") #ion: expansion error: split_at: requires an argument
  20. #echo @split_at("FOOBAR" "-1") #ion: expansion error: split_at: requires a valid number as an argument
  21. #echo @split_at("FOOBAR" "8") #ion: expansion error: split_at: value is out of bounds
  22. echo '# ANCHOR_END: split_at'
  23. echo '# ANCHOR: bytes'
  24. echo @bytes("onetwo")
  25. echo @bytes("abc")
  26. echo '# ANCHOR_END: bytes'
  27. echo '# ANCHOR: chars'
  28. echo @chars("onetwo")
  29. for char in @chars("foobar")
  30. echo $char
  31. end
  32. echo '# ANCHOR_END: chars'
  33. echo '# ANCHOR: graphemes'
  34. echo @graphemes("onetwo" "3")
  35. for grapheme in @graphemes("foobar")
  36. echo $grapheme
  37. end
  38. echo '# ANCHOR_END: graphemes'
  39. echo '# ANCHOR: reverse'
  40. echo @reverse([1 2 3])
  41. echo @reverse(["a"])
  42. let foo = [1 2 3]
  43. echo @reverse(@foo)
  44. echo '# ANCHOR_END: reverse'