We need a whole WithFilter class to honor the "doesn't create a new collection" contract even though it seems unlikely to matter much in a collection with max size 1.
Appliesfa if this is aFailure orfb if this is aSuccess.
Appliesfa if this is aFailure orfb if this is aSuccess. Iffb is initially applied and throws an exception, thenfa is applied with this exception.
the function to apply if this is aFailure
the function to apply if this is aSuccess
the results of applying the function
val result: Try[Int] = Try { string.toInt }log(result.fold( ex => "Operation failed with " + ex, v => "Operation produced value: " + v))Returns the value from thisSuccess or the givendefault argument if this is aFailure.
Completes thisTry by applying the functionf to this if this is of typeFailure, or conversely, by applyings if this is aSuccess.
An iterator over the names of all the elements of this product.
An iterator over the names of all the elements of this product.
An iterator over all the elements of this product.
An iterator over all the elements of this product.
in the default implementation, anIterator[Any]
Creates a non-strict filter, which eventually converts this to aFailure if the predicate is not satisfied.
Creates a non-strict filter, which eventually converts this to aFailure if the predicate is not satisfied.
Note: unlike filter, withFilter does not create a new Try. Instead, it restricts the domain of subsequentmap,flatMap,foreach, andwithFilter operations.
As Try is a one-element collection, this may be a bit overkill, but it's consistent with withFilter on Option and the other collections.
the predicate used to test elements.