diff --git a/base/src/__builtin__.act b/base/src/__builtin__.act index f11fa3952..6b59abfe5 100644 --- a/base/src/__builtin__.act +++ b/base/src/__builtin__.act @@ -840,17 +840,17 @@ extension bytes (Hashable): def abs(x : Number) -> Real: return x.__abs__() -#def all [A(value)] (it : Iterable[A]) -> bool: -# for x in it: -# if not x: -# return False -# return True - -#def any [A(value)] (it : Iterable[A]) -> bool: -# for x in it: -# if x: -# return True -# return False +def all[A(value)](it: Iterable[A]) -> bool: + for x in it: + if bool(x) == False: + return False + return True + +def any[A(value)](it: Iterable[A]) -> bool: + for x in it: + if bool(x) == True: + return True + return False def ascii(x : value) -> str: NotImplemented diff --git a/test/builtins_auto/test_all.act b/test/builtins_auto/test_all.act new file mode 100644 index 000000000..1ce7c8aea --- /dev/null +++ b/test/builtins_auto/test_all.act @@ -0,0 +1,23 @@ + + + + +def test_all1(): + stuff = [True, True, True] + if all(stuff): + return + raise ValueError("all stuff is True but all() returned False") + +def test_all2(): + stuff = [True, False, True] + if all(stuff): + raise ValueError("not all stuff is True but all() returned True") + +actor main(env): + try: + test_all1() + test_all2() + env.exit(0) + except Exception as e: + print(e) + env.exit(1) diff --git a/test/builtins_auto/test_any.act b/test/builtins_auto/test_any.act new file mode 100644 index 000000000..59dd58af6 --- /dev/null +++ b/test/builtins_auto/test_any.act @@ -0,0 +1,31 @@ + + + + +def test_any1(): + stuff = [True, True, True] + if any(stuff): + return + raise ValueError("all stuff is True but any() returned False") + +def test_any2(): + stuff = [True, False, True] + if any(stuff): + return + raise ValueError("some stuff is True but any() returned False") + +def test_any3(): + stuff = [False, False, False] + if any(stuff): + raise ValueError("no stuff is True but any() returned True") + return + +actor main(env): + try: + test_any1() + test_any2() + test_any3() + env.exit(0) + except Exception as e: + print(e) + env.exit(1)