ts-pattern icon indicating copy to clipboard operation
ts-pattern copied to clipboard

select support for array matches

Open AmirabbasJ opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe. It would be great if we could select the matched field in case of arrays too

Describe the solution you'd like honestly I'm not sure how would this be possible with the current API but maybe if it could use select as a wrapper on the cases for example in this case:

match([x, y])
      .with([when(not(isArray)), __], ([_]) => createNonArrayFailure(_))
      .with([when(not(isEmptyArray)), when(or(isNull, isUndefined))], ([_]) =>
        createEmptyArrayFailure(_))

it would be cool if I could do something like this

match([x, y])
      .with([select(when(not(isArray))), __], createNonArrayFailure)
      .with([when(not(isEmptyArray)), select(when(or(isNull, isUndefined)))], createEmptyArrayFailure)

or maybe

match([x, y])
      .with([when(not(isArray)), __], [select(), __], createNonArrayFailure)
      .with([when(not(isEmptyArray)), when(or(isNull, isUndefined))], [__, select()], createEmptyArrayFailure)

AmirabbasJ avatar Jul 08 '21 11:07 AmirabbasJ