examples/array.fy in fancy-0.3.3 vs examples/array.fy in fancy-0.4.0
- old
+ new
@@ -3,13 +3,11 @@
# create an array
arr = [1,2,3,4,5,6]
# print each element squared
-arr each: |x| {
- x squared println
-}
+arr each: @{ squared println }
# display each element with its index in the array
arr each_with_index: |x i| {
"Index " ++ i ++ " -> " ++ x println
}
@@ -19,26 +17,26 @@
# print the array of doubled elements
arr map: 'doubled . inspect println
# print array of all elements smaller than 4
-arr select: |x| { x < 4 } . inspect println
+arr select: @{ < 4 } . inspect println
# print array of all elements that are not smaller than 4
-arr reject: |x| { x < 4 } . inspect println
+arr reject: @{ < 4 } . inspect println
# prints: [5, 6]
-arr take_while: |x| { x < 5 } . inspect println
+arr take_while: @{ < 5 } . inspect println
"testing reduce:init_val: " print
arr reduce: |acc x| { acc * x } init_val: 1 . println # same as: 1*1*2*3*4*5*6
"testing any?: " print
-arr any?: |x| { x > 3 } . println # prints: true
+arr any?: @{ > 3 } . println # prints: true
"testing all?: " print
-arr all?: |x| { x < 7 } . println # prints: true
+arr all?: @{ < 7 } . println # prints: true
"testing from:to: " print
arr [[3,5]] . inspect println # prints: [4, 5, 6]
# some other handy methods
@@ -47,6 +45,6 @@
"testing to_s: " print
arr to_s println # prints: 123456
"testing inspect: " print
-arr inspect println # prints: [1, 2, 3, 4, 5, 6] : Array
+arr inspect println # prints: [1, 2, 3, 4, 5, 6]