is there a way of having a dispatch table like tha...
# announcements
m
is there a way of having a dispatch table like that without the
!!
all over the place?
Copy code
val extractor = when {
            config.contains(REGEX) && config.contains(FORMAT)  -> FormatAndRegexExtractor(config[REGEX]!!, config[FORMAT]!!)
            config.contains(REGEX) && !config.contains(FORMAT) -> NamedCaptureGroupExtractor(config[REGEX]!!)
            config.contains(DELIMS) && config.contains(FIELDS) -> DelimiterExtractor(config[DELIMS]!!, config[FIELDS]!!)
            else                                               -> throw IllegalArgumentException("can not process this configuration: $config")
        }
d
assign the value of
config[REGEX]
to a local variable before the when. This way the compiler should be able to smart cast it
m
thanks 🙂 code looks good in the way you've described