madlib icon indicating copy to clipboard operation
madlib copied to clipboard

Feature Request: sugar for automatic indexing of constructor parameters

Open brekk opened this issue 2 years ago • 0 comments

Original comment which sparked more discussion in Slack:

I’m writing a decent amount of stuff that I think a compiler could do for me:

canAfford :: Integer -> ThingWithMoney -> Boolean
export canAfford = (cost, monied) =>
  where (monied) {
    Monied(_, x, _) => x - cost >= 0
  }

I’d love if there was a generic syntactic means of the same:

canAfford = (cost, raw) => pipe(
  mapField(1, (x) => x - cost >= 0),
)(raw)

where mapField understands the order of arguments for a given monad / container

Additionally one of the possible affordances here would be that you can modify a single field with a function while keeping everything else the same.

Also proposed:

  • Monied[1]
  • .1 / Monied.1

brekk avatar Dec 22 '22 18:12 brekk