home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-12 | 810 b | 31 lines |
- // Copyright(c) 1996 ObjectSpace, Inc.
- import jgl.*;
-
- public class Algorithms1
- {
- public static void main( String[] args )
- {
- Array array1 = new Array();
- array1.add( "cat" );
- array1.add( "monkey" );
- array1.add( "goat" );
- Applying.forEach( array1, new PrintFunction() );
-
- SList list = new SList();
- list.add( new Integer( 3 ) );
- list.add( new Integer( 7 ) );
- list.add( new Integer( 4 ) );
- Integer total = (Integer) Applying.inject( list, new Integer( 0 ), new PlusInteger() );
- System.out.println( "list = " + list + ", total = " + total );
- }
- }
-
- class PrintFunction implements UnaryFunction
- {
- public Object execute( Object object )
- {
- System.out.println( "PRINT " + object );
- return null; // Not used.
- }
- }
-