# scan -- apply a function to each element in a list or sequence

## Synopsis

• Usage:
scan(L, f)
scan(L, L', f)
scan(n, f)
• Inputs:

## Description

scan(L, f) applies the function f to each element of the list L. The function values are discarded.

 i1 : scan({a, 4, "George", 2^100}, print) a 4 George 1267650600228229401496703205376 i2 : scan("foo", print) f o o

scan(n, f) applies the function f to each element of the list 0, 1, ..., n-1

 i3 : scan(4, print) 0 1 2 3 i4 : v = {a,b,c}; scan(#v, i -> print(i,v#i)) (0, a) (1, b) (2, c)

The keyword break can be used to terminate the scan prematurely, and optionally to specify a return value for the expression. Here we use it to locate the first even number in a list.

 i6 : scan({3,5,7,11,44,55,77}, i -> if even i then break i) o6 = 44

• apply -- apply a function to each element
• accumulate -- apply a binary operator repeatedly
• fold -- apply a binary operator repeatedly
• lists and sequences -- a detailed overview of lists and sequences in Macaulay2

## Ways to use scan :

• "scan(BasicList,BasicList,Function)"
• "scan(BasicList,Function)"
• "scan(String,Function)"
• "scan(ZZ,Function)"

## For the programmer

The object scan is .