std: remove foldr and alli methods in vec
This commit is contained in:
parent
ed299af625
commit
513d2292e5
@ -351,6 +351,7 @@ a single large vector of floats. Each task needs the full vector to perform its
|
||||
# use std::vec;
|
||||
# use std::uint;
|
||||
# use std::rand;
|
||||
# use std::iterator::IteratorUtil;
|
||||
use extra::arc::ARC;
|
||||
|
||||
fn pnorm(nums: &~[float], p: uint) -> float {
|
||||
|
@ -19,6 +19,7 @@ use middle::typeck::method_map;
|
||||
use middle::moves;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
use extra::sort;
|
||||
@ -242,7 +243,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
|
||||
not_useful
|
||||
}
|
||||
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
|
||||
let max_len = do m.foldr(0) |r, max_len| {
|
||||
let max_len = do m.rev_iter().fold(0) |max_len, r| {
|
||||
match r[0].node {
|
||||
pat_vec(ref before, _, ref after) => {
|
||||
uint::max(before.len() + after.len(), max_len)
|
||||
|
@ -110,6 +110,7 @@ use middle::ty;
|
||||
use middle::typeck;
|
||||
use middle::moves;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::cast::transmute;
|
||||
use core::hashmap::HashMap;
|
||||
use core::io;
|
||||
@ -923,7 +924,7 @@ impl Liveness {
|
||||
pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
|
||||
do blk.node.stmts.foldr(succ) |stmt, succ| {
|
||||
do blk.node.stmts.rev_iter().fold(succ) |succ, stmt| {
|
||||
self.propagate_through_stmt(*stmt, succ)
|
||||
}
|
||||
}
|
||||
@ -977,7 +978,7 @@ impl Liveness {
|
||||
|
||||
pub fn propagate_through_exprs(&self, exprs: &[@expr], succ: LiveNode)
|
||||
-> LiveNode {
|
||||
do exprs.foldr(succ) |expr, succ| {
|
||||
do exprs.rev_iter().fold(succ) |succ, expr| {
|
||||
self.propagate_through_expr(*expr, succ)
|
||||
}
|
||||
}
|
||||
@ -1021,7 +1022,7 @@ impl Liveness {
|
||||
// the construction of a closure itself is not important,
|
||||
// but we have to consider the closed over variables.
|
||||
let caps = self.ir.captures(expr);
|
||||
do caps.foldr(succ) |cap, succ| {
|
||||
do caps.rev_iter().fold(succ) |succ, cap| {
|
||||
self.init_from_succ(cap.ln, succ);
|
||||
let var = self.variable(cap.var_nid, expr.span);
|
||||
self.acc(cap.ln, var, ACC_READ | ACC_USE);
|
||||
@ -1159,7 +1160,7 @@ impl Liveness {
|
||||
|
||||
expr_struct(_, ref fields, with_expr) => {
|
||||
let succ = self.propagate_through_opt_expr(with_expr, succ);
|
||||
do (*fields).foldr(succ) |field, succ| {
|
||||
do fields.rev_iter().fold(succ) |succ, field| {
|
||||
self.propagate_through_expr(field.node.expr, succ)
|
||||
}
|
||||
}
|
||||
@ -1215,10 +1216,10 @@ impl Liveness {
|
||||
}
|
||||
|
||||
expr_inline_asm(ref ia) =>{
|
||||
let succ = do ia.inputs.foldr(succ) |&(_, expr), succ| {
|
||||
let succ = do ia.inputs.rev_iter().fold(succ) |succ, &(_, expr)| {
|
||||
self.propagate_through_expr(expr, succ)
|
||||
};
|
||||
do ia.outputs.foldr(succ) |&(_, expr), succ| {
|
||||
do ia.outputs.rev_iter().fold(succ) |succ, &(_, expr)| {
|
||||
self.propagate_through_expr(expr, succ)
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
* taken to it, implementing them for Rust seems difficult.
|
||||
*/
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::container::Map;
|
||||
use core::libc::c_ulonglong;
|
||||
use core::option::{Option, Some, None};
|
||||
@ -176,7 +177,7 @@ fn represent_type_uncached(cx: @CrateContext, t: ty::t) -> Repr {
|
||||
// Since there's at least one
|
||||
// non-empty body, explicit discriminants should have
|
||||
// been rejected by a checker before this point.
|
||||
if !cases.alli(|i,c| c.discr == (i as int)) {
|
||||
if !cases.iter().enumerate().all(|(i,c)| c.discr == (i as int)) {
|
||||
cx.sess.bug(fmt!("non-C-like enum %s with specified \
|
||||
discriminants",
|
||||
ty::item_path_str(cx.tcx, def_id)))
|
||||
|
@ -20,7 +20,6 @@ use middle::trans::common::{T_array, T_ptr, T_void};
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::option::{Option, None, Some};
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
|
||||
fn align_up_to(off: uint, a: uint) -> uint {
|
||||
return (off + a - 1u) / a * a;
|
||||
|
@ -1821,11 +1821,9 @@ pub trait ImmutableVector<'self, T> {
|
||||
fn last_opt(&self) -> Option<&'self T>;
|
||||
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
|
||||
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
|
||||
fn foldr<'a, U>(&'a self, z: U, p: &fn(t: &'a T, u: U) -> U) -> U;
|
||||
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
|
||||
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
|
||||
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U];
|
||||
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
|
||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
|
||||
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
|
||||
unsafe fn unsafe_ref(&self, index: uint) -> *T;
|
||||
@ -1913,12 +1911,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
rposition(*self, f)
|
||||
}
|
||||
|
||||
/// Reduce a vector from right to left
|
||||
#[inline]
|
||||
fn foldr<'a, U>(&'a self, z: U, p: &fn(t: &'a T, u: U) -> U) -> U {
|
||||
self.rev_iter().fold(z, |u, t| p(t, u))
|
||||
}
|
||||
|
||||
/// Apply a function to each element of a vector and return the results
|
||||
#[inline]
|
||||
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
|
||||
@ -1942,14 +1934,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
r
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the function returns true for all elements.
|
||||
*
|
||||
* If the vector is empty, true is returned.
|
||||
*/
|
||||
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
|
||||
self.iter().enumerate().all(|(i, t)| f(i,t))
|
||||
}
|
||||
/**
|
||||
* Apply a function to each element of a vector and return a concatenation
|
||||
* of each result vector
|
||||
|
@ -20,6 +20,7 @@ use opt_vec;
|
||||
use parse::token;
|
||||
use visit;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::hashmap::HashMap;
|
||||
use core::int;
|
||||
use core::option;
|
||||
@ -833,7 +834,7 @@ mod test {
|
||||
// returning the resulting index
|
||||
fn unfold_test_sc(tscs : ~[TestSC], tail: SyntaxContext, table : &mut SCTable)
|
||||
-> SyntaxContext {
|
||||
tscs.foldr(tail, |tsc : &TestSC,tail : SyntaxContext|
|
||||
tscs.rev_iter().fold(tail, |tail : SyntaxContext, tsc : &TestSC|
|
||||
{match *tsc {
|
||||
M(mrk) => new_mark_internal(mrk,tail,table),
|
||||
R(ident,name) => new_rename_internal(ident,name,tail,table)}})
|
||||
@ -874,7 +875,7 @@ mod test {
|
||||
// extend a syntax context with a sequence of marks given
|
||||
// in a vector. v[0] will be the outermost mark.
|
||||
fn unfold_marks(mrks:~[Mrk],tail:SyntaxContext,table: &mut SCTable) -> SyntaxContext {
|
||||
mrks.foldr(tail, |mrk:&Mrk,tail:SyntaxContext|
|
||||
mrks.rev_iter().fold(tail, |tail:SyntaxContext, mrk:&Mrk|
|
||||
{new_mark_internal(*mrk,tail,table)})
|
||||
}
|
||||
|
||||
|
@ -1025,11 +1025,11 @@ pub fn cs_fold(use_foldl: bool,
|
||||
match *substructure.fields {
|
||||
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
|
||||
if use_foldl {
|
||||
do all_fields.foldl(base) |&old, &(_, self_f, other_fs)| {
|
||||
do all_fields.iter().fold(base) |old, &(_, self_f, other_fs)| {
|
||||
f(cx, span, old, self_f, other_fs)
|
||||
}
|
||||
} else {
|
||||
do all_fields.foldr(base) |&(_, self_f, other_fs), old| {
|
||||
do all_fields.rev_iter().fold(base) |old, &(_, self_f, other_fs)| {
|
||||
f(cx, span, old, self_f, other_fs)
|
||||
}
|
||||
}
|
||||
@ -1094,11 +1094,11 @@ pub fn cs_same_method_fold(use_foldl: bool,
|
||||
cs_same_method(
|
||||
|cx, span, vals| {
|
||||
if use_foldl {
|
||||
do vals.foldl(base) |&old, &new| {
|
||||
do vals.iter().fold(base) |old, &new| {
|
||||
f(cx, span, old, new)
|
||||
}
|
||||
} else {
|
||||
do vals.foldr(base) |&new, old| {
|
||||
do vals.rev_iter().fold(base) |old, &new| {
|
||||
f(cx, span, old, new)
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ library.
|
||||
*/
|
||||
|
||||
use core::prelude::*;
|
||||
use core::iterator::IteratorUtil;
|
||||
|
||||
use ast::{enum_def, ident, item, Generics, meta_item, struct_def};
|
||||
use ext::base::ExtCtxt;
|
||||
@ -74,7 +75,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt,
|
||||
in_items
|
||||
}
|
||||
meta_list(_, ref titems) => {
|
||||
do titems.foldr(in_items) |&titem, in_items| {
|
||||
do titems.rev_iter().fold(in_items) |in_items, &titem| {
|
||||
match titem.node {
|
||||
meta_name_value(tname, _) |
|
||||
meta_list(tname, _) |
|
||||
|
@ -363,7 +363,7 @@ fn validate(edges: ~[(node_id, node_id)],
|
||||
|
||||
info!(~"Verifying tree edges...");
|
||||
|
||||
let status = do tree.alli() |k, parent| {
|
||||
let status = do tree.iter().enumerate().all |(k, parent)| {
|
||||
if *parent != root && *parent != -1i64 {
|
||||
level[*parent] == level[k] - 1
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ fn main() {
|
||||
let needlesArr: ~[char] = ~['a', 'f'];
|
||||
do needlesArr.iter().fold() |x, y| {
|
||||
}
|
||||
//~^ ERROR 1 parameter were supplied (including the closure passed by the `do` keyword)
|
||||
//~^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword)
|
||||
//
|
||||
// the first error is, um, non-ideal.
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
use std::iterator::IteratorUtil;
|
||||
|
||||
pub fn main() {
|
||||
let v = ~[-1f, 0f, 1f, 2f, 3f];
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
use std::iterator::IteratorUtil;
|
||||
|
||||
pub fn main() {
|
||||
fn f(i: &fn() -> uint) -> uint { i() }
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
use std::iterator::IteratorUtil;
|
||||
|
||||
pub fn main() {
|
||||
fn f(i: uint) -> uint { i }
|
||||
|
Loading…
x
Reference in New Issue
Block a user