From 2833ca478c19d2f8f150570a6d60b93488debdcc Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 16 Dec 2011 06:27:50 -0800 Subject: reorder args to the various vec, option fns so blk comes last --- src/libcore/option.rs | 6 +++--- src/libcore/vec.rs | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 403cb47f47e..b46798894b7 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -36,7 +36,7 @@ fn get(opt: t) -> T { /* */ -fn map(f: block(T) -> U, opt: t) -> t { +fn map(opt: t, f: block(T) -> U) -> t { alt opt { some(x) { some(f(x)) } none. { none } } } @@ -70,7 +70,7 @@ Function: maybe Applies a function to the contained value or returns a default */ -fn maybe(def: U, f: block(T) -> U, opt: t) -> U { +fn maybe(def: U, opt: t, f: block(T) -> U) -> U { alt opt { none. { def } some(t) { f(t) } } } @@ -80,7 +80,7 @@ Function: may Performs an operation on the contained value or does nothing */ -fn may(f: block(T), opt: t) { +fn may(opt: t, f: block(T)) { alt opt { none. {/* nothing */ } some(t) { f(t); } } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index d8f89b3b27b..9fe10692cc6 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -384,7 +384,7 @@ Function: map Apply a function to each element of a vector and return the results */ -fn map(f: block(T) -> U, v: [T]) -> [U] { +fn map(v: [T], f: block(T) -> U) -> [U] { let result = []; reserve(result, len(v)); for elem: T in v { result += [f(elem)]; } @@ -396,7 +396,7 @@ Function: map_mut Apply a function to each element of a mutable vector and return the results */ -fn map_mut(f: block(T) -> U, v: [const T]) -> [U] { +fn map_mut(v: [const T], f: block(T) -> U) -> [U] { let result = []; reserve(result, len(v)); for elem: T in v { @@ -411,7 +411,7 @@ Function: map2 Apply a function to each pair of elements and return the results */ -fn map2(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] { +fn map2(v0: [T], v1: [U], f: block(T, U) -> V) -> [V] { let v0_len = len(v0); if v0_len != len(v1) { fail; } let u: [V] = []; @@ -428,7 +428,7 @@ Apply a function to each element of a vector and return the results If function `f` returns `none` then that element is excluded from the resulting vector. */ -fn filter_map(f: block(T) -> option::t, v: [const T]) +fn filter_map(v: [const T], f: block(T) -> option::t) -> [U] { let result = []; for elem: T in v { @@ -449,7 +449,7 @@ holds. Apply function `f` to each element of `v` and return a vector containing only those elements for which `f` returned true. */ -fn filter(f: block(T) -> bool, v: [T]) -> [T] { +fn filter(v: [T], f: block(T) -> bool) -> [T] { let result = []; for elem: T in v { if f(elem) { result += [elem]; } @@ -474,7 +474,7 @@ Function: foldl Reduce a vector from left to right */ -fn foldl(p: block(T, U) -> T, z: T, v: [const U]) -> T { +fn foldl(z: T, v: [const U], p: block(T, U) -> T) -> T { let accum = z; iter(v) { |elt| accum = p(accum, elt); @@ -487,7 +487,7 @@ Function: foldr Reduce a vector from right to left */ -fn foldr(p: block(T, U) -> U, z: U, v: [const T]) -> U { +fn foldr(v: [const T], z: U, p: block(T, U) -> U) -> U { let accum = z; riter(v) { |elt| accum = p(elt, accum); @@ -502,7 +502,7 @@ Return true if a predicate matches any elements If the vector contains no elements then false is returned. */ -fn any(f: block(T) -> bool, v: [T]) -> bool { +fn any(v: [T], f: block(T) -> bool) -> bool { for elem: T in v { if f(elem) { ret true; } } ret false; } @@ -514,7 +514,7 @@ Return true if a predicate matches all elements If the vector contains no elements then true is returned. */ -fn all(f: block(T) -> bool, v: [T]) -> bool { +fn all(v: [T], f: block(T) -> bool) -> bool { for elem: T in v { if !f(elem) { ret false; } } ret true; } @@ -549,7 +549,7 @@ Apply function `f` to each element of `v`, starting from the first. When function `f` returns true then an option containing the element is returned. If `f` matches no elements then none is returned. */ -fn find(f: block(T) -> bool, v: [T]) -> option::t { +fn find(v: [T], f: block(T) -> bool) -> option::t { for elt: T in v { if f(elt) { ret some(elt); } } ret none; } @@ -575,7 +575,7 @@ Function: position_pred Find the first index for which the value matches some predicate */ -fn position_pred(f: block(T) -> bool, v: [T]) -> option::t { +fn position_pred(v: [T], f: block(T) -> bool) -> option::t { let i: uint = 0u; while i < len(v) { if f(v[i]) { ret some::(i); } i += 1u; } ret none; -- cgit 1.4.1-3-g733a5