You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the work on this type. I try to replace Swift throws with Result in one of my projects, but on every higher order function I'm stopped. The project depends on the behavior of map and that it's transform function can throw. So I wrote a map that can do this with Result. Here is my implementation (not that functional):
extensionSequence{
/// Returns an array containing the results of mapping the given closure
/// over the sequence's elements.
///
/// - Parameter transform: A mapping closure. `transform` accepts an
/// element of this sequence as its parameter and returns a transformed
/// value of the same or of a different type wrapped in a `Result`.
/// - Returns: A `Result` containing an array of the transformed elements of this
/// sequence or the error of the first `failure` that occured by applying `transform`.
func tryMap<T, E>(transform:(Self.Iterator.Element)->Result<T,E>)->Result<[T],E>{vartransformedElements=[T]()
for element in self{
switch transform(element){case.success(let transformed):
transformedElements.append(transformed)case.failure(let error):return.failure(error)}}return.success(transformedElements)}}
So without a Result version of all these standard library functions that can throw I doubt that I can use the Result type to it's full extend. Is there some library that can help me out here?
The text was updated successfully, but these errors were encountered:
torstenlehmann
changed the title
Support for higher order functions that can throw.
Support for higher order functions that can throw
Apr 24, 2017
Kind of bumping this. It would make sense for the map/flatMap functions to be rethrowing and in the case of an error thrown, to make it return a failure. Not sure how typed errors would affect this, but it would also behave more like the Swift STL handles its higher order functions.
Thanks for the work on this type. I try to replace Swift
throws
withResult
in one of my projects, but on every higher order function I'm stopped. The project depends on the behavior ofmap
and that it'stransform
function can throw. So I wrote a map that can do this withResult
. Here is my implementation (not that functional):So without a
Result
version of all these standard library functions that can throw I doubt that I can use theResult
type to it's full extend. Is there some library that can help me out here?The text was updated successfully, but these errors were encountered: