Hi Everyone,
I recently wrote this code in python (I’m enjoying learning how to write code in a functional manner) that returns whatever numbers are at the end of a string (fails out if there aren’t any).
from functools import reduce
from operator import add
def get_num_from_end_of_string(string: str) -> int:
backward_nums = list(filter(picky_digit, reversed(string)))
return int(reduce(add, reversed(backward_nums)))
def picky_digit(s: str) -> bool:
if s.isdigit():
return True
else:
raise StopIteration
And I’d like to learn how to write something similar in Julia. In a looped version of this, I would put a break
after we stop getting digits. In Python I mimic the break
with a StopIteration
. How can I do this in Julia?
(Any suggestions to make the Python version better are also welcome)