Skip to content

possible new iterator #1

@jcupitt

Description

@jcupitt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions