tracks/fsharp/exercises/beer-song/Example.fs in trackler-2.2.1.62 vs tracks/fsharp/exercises/beer-song/Example.fs in trackler-2.2.1.63
- old
+ new
@@ -1,15 +1,21 @@
module BeerSong
-let verse n =
+let private verse n =
match n with
- | 0 -> "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
- | 1 -> "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n"
- | 2 -> "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n"
- | _ -> sprintf "%d bottles of beer on the wall, %d bottles of beer.\nTake one down and pass it around, %d bottles of beer on the wall.\n" n n (n-1)
+ | 0 ->
+ [ "No more bottles of beer on the wall, no more bottles of beer.";
+ "Go to the store and buy some more, 99 bottles of beer on the wall." ]
+ | 1 ->
+ [ "1 bottle of beer on the wall, 1 bottle of beer.";
+ "Take it down and pass it around, no more bottles of beer on the wall." ]
+ | 2 ->
+ [ "2 bottles of beer on the wall, 2 bottles of beer.";
+ "Take one down and pass it around, 1 bottle of beer on the wall." ]
+ | _ ->
+ [ sprintf "%d bottles of beer on the wall, %d bottles of beer." n n;
+ sprintf "Take one down and pass it around, %d bottles of beer on the wall." (n-1) ]
-let verses stop start =
- [stop .. -1 .. start]
+let recite startBottles takeDown =
+ [startBottles .. -1 .. (startBottles - takeDown + 1)]
|> List.map verse
- |> String.concat "\n"
-
-let sing = verses 99 0
+ |> List.reduce (fun x y -> x @ "" :: y)
\ No newline at end of file