Skip to content

When Iterate is not clear enough .... #454

Description

@Maatary

Generates a potentially infinite stream of promises by repeatedly calling f until predicate becomes true.

Where:

f - function that, given a seed, returns the next value or a promise for it.
predicate - function that receives the current iteration value, and should return truthy when the unfold should stop
***handler - function that receives each value as it is produced by f. It may return a promise to delay the next iteration.
seed - initial value provided to the handler, and first f invocation. May be a promise.

The question is what is handler for exactly ?

In my case:

1 - i have a table of values

2 - for each value i need to check if a value X, is not related to the value of the tables.

2.2 - In that respect obtaining the related element of a value requires making an AJAX call.

2.3 - Then upon getting the result of related value, i check if the value X is not in that result.

2.4 - If it is i'm done. If not i repeat the task with the next value in the table.

I have the feeling that iterate is suited for that.

1 - However i don't understand how the handler can help me.

2 - I feel one could give as a seed, an object {table: tab, iter: 0}, then the next function would simply change the iter value and return the object.

3 - The issue is with predicate and handler.

3.1 - I need to make an ajax call, get my result and compare. Can the result of predicate be a promise ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions