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

possible new iterator #1

Open
jcupitt opened this issue Apr 23, 2017 · 0 comments
Open

possible new iterator #1

jcupitt opened this issue Apr 23, 2017 · 0 comments

Comments

@jcupitt
Copy link

jcupitt commented Apr 23, 2017

Hello, I also use glib in a somewhat functional style. The most useful primitive I've found is a simple iterator with a function argument:

https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/util.c#L114

It walks down the GSList calling a function for every data element, stopping either when the list is exhausted (in which case it returns NULL) or stopping when the function returns non-NULL and returning that value. It's somewhat like find, I suppose, or forall, but with early termination.

It takes a shallow copy of the list, so the callback can modify the list if it wishes. Since it uses NULL to mean terminate, the list cannot contain NULL values, but I've not found this a problem in practice.

Anyway, another possibility.

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

1 participant