diff --git a/sisyphus/delayed_ops.py b/sisyphus/delayed_ops.py index 222c530..d3f68e1 100644 --- a/sisyphus/delayed_ops.py +++ b/sisyphus/delayed_ops.py @@ -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]) + diff --git a/tests/delayed_ops_unittest.py b/tests/delayed_ops_unittest.py index abe1f26..597d876 100644 --- a/tests/delayed_ops_unittest.py +++ b/tests/delayed_ops_unittest.py @@ -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'))