diff --git a/Sources/Parameterize/Params.swift b/Sources/Parameterize/Params.swift index 9343301..0b2dfe5 100644 --- a/Sources/Parameterize/Params.swift +++ b/Sources/Parameterize/Params.swift @@ -36,47 +36,25 @@ extension Params: ParameterPair { } var value: Any? { - if let mapper = mapper { - return process(mappedValue: mapper(wrappedValue)) - } else { - return processWrappedValue() - } - } - - /// Two functions below have completely the same body - /// but it required to split to 2 functions - /// because with `wrappedValue`, we need to directly access - /// instead of go through `Any?` parameter, - /// or else it will be wrapped into an `Optional` type - /// and produces incorrect output. - - private func processWrappedValue() -> Any? { var v: Any? - if let value = wrappedValue as? OptionalProtocol { - v = value.wrapped - } else { - v = wrappedValue - } + // go through this value to eliminate optional + let underlyingValue: Any - if let value = v as? ParamConvertible { - v = value.parameterValue + if let mapper = mapper { + underlyingValue = mapper(wrappedValue) as Any + } else { + underlyingValue = wrappedValue } - return v - } - - private func process(mappedValue: Any?) -> Any? { - var v: Any? - - if let value = mappedValue as? OptionalProtocol { + if let value = underlyingValue as? OptionalProtocol { v = value.wrapped } else { - v = mappedValue + v = underlyingValue } if let value = v as? ParamConvertible { - v = value.parameterValue + v = value.parameterValue as Any } return v