netceteragroup / skele

Architectural framework that assists building data-driven apps with React or React Native.
MIT License
163 stars 32 forks source link

feat(core): Implement reduce for zippers #88

Closed andon closed 6 years ago

andon commented 6 years ago

Adds the following methods in zip (they are curried):

declare function reduce<T>(
  fn: (acc: T, item: any) => T,
  initialAcc: T,
  zipper: Zipper
): T
declare function reducePre<T>(
  fn: (acc: T, item: any) => T,
  initialAcc: T,
  zipper: Zipper
): T

These functions preform a reduction of the zipper tree in post (reduce) or pre (reducePre) order.

Also, the following method is added in data:

declare function when<T>(
  pred: (item: any) => Boolean),
  fn: (acc: T, item: any) => T
): (acc: T, item:any) => T

It helps writing zip reducing using a predicate.

Closes https://github.com/netceteragroup/girders-elements/issues/82

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.1%) to 83.08% when pulling df19b704b4286feaa4ce865e8c32ce0ce96a7f3a on features/zip-reduce into a06893a13ab62d9e554ecaf65c7659dba3a40f51 on master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.1%) to 83.08% when pulling 3759e648ec6ef6ee12e61619a706a849b6a21990 on features/zip-reduce into a06893a13ab62d9e554ecaf65c7659dba3a40f51 on master.