27.29 First

First( list, func )

First returns the first element of the list list for which the unary function func returns true. list may contain holes. func must return either true or false for every element of list, otherwise an error is signalled. If func returns false for every element of list an error is signalled.

    gap> First( [10^7..10^8], IsPrime );
    10000019
    gap> First( [10^5..10^6],
    >           n -> not IsPrime(n) and IsPrimePowerInt(n) );
    100489 

PositionProperty (see PositionProperty) allows you to find the position of the first element in a list that satisfies a certain property.

Previous Up Top Next
Index

GAP 3.4.4
April 1997