Q: Transform Reactive Cocoa SignalProducer into enum I'm trying to transform my API SignalProducers into an enum so I get Loading, Failed and Loaded states. Enum is:
enum DataLoadState<DataType>{
    case Loading
    case Failed
    case Loaded(DataType)
}

To do it I transform my SignalProducer to a NoError producer and start with loading state:
extension SignalProducerType{
    func materializeToLoadState() -> SignalProducer<DataLoadState<Value>,NoError>{
        let producer = self
        .map(DataLoadState.Loaded)
        .startWithValue(DataLoadState.Loading)

        return producer.ignoreErrors(replacementValue:DataLoadState<Value>.Failed)
    }
}

extension SignalProducerType {

    func startWithValue(value:Value)->SignalProducer<Value,Error>{
        return SignalProducer(value:value).concat(self.producer)
    }

    public func ignoreErrors(replacementValue replacementValue: Self.Value? = nil) -> SignalProducer<Self.Value, NoError> {
        return self.flatMapError { error in
            return replacementValue.map(SignalProducer.init) ?? .empty
        }
    }
}

It works but I don't want to ignore Errors, instead I want to include it in the failed case:
enum DataLoadState<DataType>{
    case Loading
    case Failed(APIError?)
    case Loaded(DataType)
}

Any idea on how can I use flatMapError (like in ignoreError) so errors are fired as DataLoadState.Failed(error) instead of being ignored? When error isn't display error is could be just nil. Is it even possible?

A: Ok, fixed it just with:
producer.flatMapError { error in SignalProducer(value:.Failed(error as? APIError)) }

