Changeset 17865
- Timestamp:
- 09/16/07 01:53:07 (14 months ago)
- Files:
-
- 3 modified
-
src/Pugs/Prim.hs (modified) (3 diffs)
-
src/Pugs/Prim/List.hs (modified) (2 diffs)
-
t/builtins/lists/first.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim.hs
r17701 r17865 1040 1040 op2 "pick" = op2Pick 1041 1041 op2 "grep" = op2Grep 1042 op2 "first" = op2First 1042 1043 op2 "map" = op2Map 1043 1044 op2 "join" = op2Join … … 1902 1903 \\n List pre map safe (Code, List)\ 1903 1904 \\n List pre grep safe (Code, List)\ 1905 \\n Scalar pre first safe (Code, List)\ 1904 1906 \\n List pre sort safe (Code, List)\ 1905 1907 \\n List pre reduce safe (Code, List)\ … … 1908 1910 \\n List pre map safe (Array: Code)\ 1909 1911 \\n List pre grep safe (Array: Code)\ 1912 \\n Scalar pre first safe (Array: Code)\ 1910 1913 \\n List pre sort safe (Array: Code)\ 1911 1914 \\n List pre reduce safe (Array: Code)\ -
src/Pugs/Prim/List.hs
r16573 r17865 5 5 op1Min, op1Max, op1Uniq, 6 6 op2Pick, 7 op2ReduceL, op2Reduce, op2Grep, op2 Map, op2Join,7 op2ReduceL, op2Reduce, op2Grep, op2First, op2Map, op2Join, 8 8 sortByM, 9 9 op1HyperPrefix, op1HyperPostfix, op2Hyper, … … 331 331 return $ VList vals 332 332 333 op2First :: Val -> Val -> Eval Val 334 op2First sub@(VCode _) list = op2First list sub 335 op2First list sub = do 336 (VList vals) <- (op2Grep list sub) 337 if (length vals) > 0 338 then return $ (vals !! 0) 339 else fail $ "Cannot call first() with a filter that removes all elements from the input list" 340 333 341 op2Map :: Val -> Val -> Eval Val 334 342 op2Map sub@(VCode _) list = op2Map list sub -
t/builtins/lists/first.t
r16466 r17865 10 10 =cut 11 11 12 plan 6;12 plan 7; 13 13 14 14 my @list = (1 .. 10); … … 16 16 { 17 17 my $result = first { ($_ % 2) }, @list; 18 ok ($result ~~ Item, "first() returns an Item");19 is ($result, 1, "returned value by first() is correct");18 ok($result ~~ Item, "first() returns an Item"); 19 is($result, 1, "returned value by first() is correct"); 20 20 } 21 21 22 22 { 23 23 my $result = @list.first( { ($_ == 4)}); 24 ok ($result ~~ Item, "method form of first returns an item");25 is ($result, 4, "method form of first returns the expected item");24 ok($result ~~ Item, "method form of first returns an item"); 25 is($result, 4, "method form of first returns the expected item"); 26 26 } 27 27 28 28 { 29 my $result = @list. grep():{ ($_ == 4) };30 ok($result ~~ Item, "first(): {block}returns an Item");29 my $result = @list.first():{ ($_ == 4) }; 30 ok($result ~~ Item, "first():<block> returns an Item"); 31 31 is($result, 4, "first() returned the expected value"); 32 32 } 33 33 34 { 35 dies_ok { @list.first( { ($_ == 11) } ) }, "first should fail if there is no first element"; 36 }
