Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducer built-ins #143

Open
ericelliott opened this issue Nov 22, 2018 · 8 comments
Open

Reducer built-ins #143

ericelliott opened this issue Nov 22, 2018 · 8 comments

Comments

@ericelliott
Copy link
Owner

ericelliott commented Nov 22, 2018

I use reducers all the time, and frequently use type parameters in documentation named "reducer", and "foldable". It would probably be a good idea to formally define them.

interface Reducible {
  reduce?: ((a?, c?, i: Number, Foldable) => a, initial: Any) => Any
}

interface Foldable = Reducible | Iterable

interface Reducer = (a?, c?, i: Number, Foldable) => a

Example

Transducer = Reducer => Reducer

createTransducer = ({
  step: Reducer,
  init?: Reducer,
  result?: Reducer,
  next?: Reducer
}) => Reducer => Reducer

transduce = (Reducer, initial: Any, xform: Transducer, Foldable) => Any

Mappable

interface Mappable {
  map: Functor(a) ~> (a => b) => Functor(b)
}

Change IterableObject to Iterable

I know it's a breaking change, but AFAIK, there's not a lot of software relying on this, yet.

@Mouvedia
Copy link
Collaborator

Mouvedia commented Nov 22, 2018

  1. where's mappable?
  2. shouldn't it be capitalized?

@ericelliott
Copy link
Owner Author

Yes, I think we should also add mappable/functor (aliased).

This proposal defines "foldable", "reducer", "iterator" and "iterable" (just in case the last two aren't defined yet — they're ES2015 built-in interfaces.

@ericelliott
Copy link
Owner Author

ericelliott commented Nov 22, 2018

I'm on the fence. The ECMAScript spec does not capitalize these kinds of types, though they do capitalize all the built-in constructors. Should we follow the same convention? I have been lowercasing all types that are NOT built-in constructors, except for Any and Void, I think.

actually, I think the idea to alias "Functor" is probably a bad one. I'd rather reserve that for the higher-kinded type constructor, e.g.:

map = (a => b) => Functor(a) => Functor(b)

@Mouvedia
Copy link
Collaborator

Mouvedia commented Nov 22, 2018

I don't have an opinion on this new builtin but it should match our builtin types if its addition is warranted.

Any, Void, Iterable, Predicate, TypedArray are all capitalized.

@ericelliott
Copy link
Owner Author

OK, I'm on board. Capitalize all the things!

@Mouvedia
Copy link
Collaborator

I think the idea to alias

You should propose these aliases separately; keep it simple for now.

interface Foldable = Reducible | Iterable;

I find this confusing; a lot of people think of fold as an alias of reduce.

@ericelliott
Copy link
Owner Author

ericelliott commented Nov 22, 2018

Anything that can be iterated can also be reduced. You just have to bring your own reduce() to the party if the method is missing.

But you're right. I should leave that off.

Oops. Can't leave it off, or it won't work for transducers or a pure reduce() definition.

@ericelliott
Copy link
Owner Author

Related: #120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants