// --------------------------------------------------------------------------
        // Section Using immutable data structures

        // NOTE: The following two functions aren't included in the book text

        // Returns places as an immutable list
        static IEnumerable <string> LoadImmutablePlaces()
        {
            return(FuncList.Cons("Cambridge", FuncList.Cons("Grantchester",
                                                            FuncList.Cons("New York", FuncList.Cons("Prague",
                                                                                                    FuncList.Cons("Seattle", FuncList.Empty <string>()))))));
        }
Example #2
0
 public override TranslationState VisitTextPart(TextPart part, TranslationState ctx)
 {
     ctx.Result = FuncList.Cons(new TextElement(part.Text, ctx.Rect), FuncList.Empty <ScreenElement>());
     return(ctx);
 }
        static void AggregateMain()
        {
            // Initialize a sample list
            var list = FuncList.Cons(1, FuncList.Cons(2, FuncList.Cons(3,
                                                                       FuncList.Cons(4, FuncList.Cons(5, FuncList.Empty <int>())))));

            // Multiply and sum elements
            //   the first call prints 15, the second 120
            Console.WriteLine(AggregateList(list, 0, Add));
            Console.WriteLine(AggregateList(list, 1, Mul));
        }
Example #4
0
 public override TranslationState VisitImagePart(ImagePart part, TranslationState ctx)
 {
     ctx.Result = FuncList.Cons(new ImageElement(part.Url, ctx.Rect), FuncList.Empty <ScreenElement>());
     return(ctx);
 }
        static void ListsMain()
        {
            // Create a list storing 1,2,3,4,5
            var list = FuncList.Cons(1, FuncList.Cons(2, FuncList.Cons(3,
                                                                       FuncList.Cons(4, FuncList.Cons(5, FuncList.Empty <int>())))));

            // Calculates and prints "15"
            int sum = SumList(list);

            Console.WriteLine(sum);
        }