calmm-js / partial.lenses

Partial lenses is a comprehensive, high-performance optics library for JavaScript
MIT License
915 stars 36 forks source link

Allow grouping cases in `L.iftes` #134

Closed polytypic closed 6 years ago

polytypic commented 6 years ago

Without grouping (up to v13.0.0):

const functions = L.lazy(rec =>
  L.iftes(
    R.is(Function), [],
    R.is(Array), [L.elems, rec],
    R.is(Object), [L.values, rec]
  )
)

With grouping:

const functions = L.lazy(rec =>
  L.iftes(
    [R.is(Function), []],
    [R.is(Array), [L.elems, rec]],
    [R.is(Object), [L.values, rec]]
  )
)

It might be possible to support both syntaxes without a lot of code, but another option is to deprecate the syntax without grouping (in which case this would be a breaking change). The grouping requires additional allocations for the groups.

This change is motivated by tools such as prettier that cannot otherwise produce readable layout on L.iftes expressions.