| 1 | # Can we define methods in pure YSH? |
| 2 | # |
| 3 | # (mylist->find(42) !== -1) |
| 4 | # |
| 5 | # instead of |
| 6 | # |
| 7 | # ('42' in mylist) |
| 8 | # |
| 9 | # Because 'in' is for Dict |
| 10 | |
| 11 | func find (haystack List, needle) { |
| 12 | for i, x in (haystack) { |
| 13 | if (x === needle) { |
| 14 | return (i) |
| 15 | } |
| 16 | } |
| 17 | return (-1) |
| 18 | } |