lazarljubenovic / jupiterate

1 stars 0 forks source link

Ditch enders, rework operators/enders/static distinction #9

Closed lazarljubenovic closed 1 year ago

lazarljubenovic commented 2 years ago

Currently, there are three types of functions:

However, enders Ender<T, U> are just a more convenient way to write static functions which accept exactly one iterable, and optionally more parameters.

For example, a static function for computing the size of an iterable has signature (iterable: Iterable<T>, options: any) => number, and is written as follows:

const count = j.s.count(j.pipe(
  [1, -1, 2, -3],
  j.filter(x => x > 0),
), options)

Note that “options“ have been added just to make the example more complete. Imagine a more complex operation. An accompanying ender would be written as follows, which is more readable:

const count = j.pipe(
  [1, -1, 2, -3],
  j.filter(x => x > 0),
  j.e.count(options),
)

Here, I propose ditching enders as separate entities and introducing a catch-all “ender” called j.andFinally which accepts a function which accepts an iterable as the first parameter, and passes the other parameters into the static function.

const count = j.pipe(
  [1, -1, 2, -3],
  j.filter(x => x > 0),
  j.andFinally(j.s.count, options),
)

With enders out of the way, we only have regular operators and static operators, which could then be distinguished by naming convention instead of by conflusing and ugly single-letter namespaces e and s.

const count = j.pipe(
  [1, -1, 2, -3],
  j.filter(x => x > 0),
  j.andFinally(j.Count, options),
)
lazarljubenovic commented 2 years ago

I forgot about generators, the fourth type of functions. However, it seems like generators are simply a specific type of static functions (they accept anything and return an iterable).

lazarljubenovic commented 1 year ago

Closed by #10.