Skip to content

Commit

Permalink
add DelayedJoin
Browse files Browse the repository at this point in the history
  • Loading branch information
JackTemaki authored and critias committed Sep 22, 2022
1 parent 08f61cf commit 5e8468d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sisyphus/delayed_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,18 @@ def __init__(self, iterable, index_start=0, index_end=-1, step=1):
def get(self):
return try_get(self.iterable)[try_get(self.index_start):try_get(self.index_end):try_get(self.step)]


class DelayedJoin(DelayedBase):

def __init__(self, iterable, separator):
"""
:param Iterable[DelayedBase|str] iterable:
:param str separator:
"""
self.iterable = iterable
self.separator = separator

def get(self):
return self.separator.join([try_get(obj) for obj in self.iterable])

4 changes: 4 additions & 0 deletions tests/delayed_ops_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def test_string(self):
self.check_only_get_eq(a[:-1], 'fooba')
self.check_only_get_eq(a[1:-1], 'ooba')

def test_join(self):
delayed_join = DelayedJoin([tk.Path("/random/path"), "/foo/bar"], ";")
self.check_only_get_eq(delayed_join, "/random/path;/foo/bar")

def test_assertions(self):
a = Delayed('foo')
self.assertRaises(AssertionError, lambda: a.function(lambda a, b: a + b, 'bar'))
Expand Down

0 comments on commit 5e8468d

Please sign in to comment.