Close a stream when test function returns truthy value