This repository was archived by the owner on Nov 18, 2022. It is now read-only.
This repository was archived by the owner on Nov 18, 2022. It is now read-only.
Highlight color problem #544
Open
Description
The highlight color of function pure
is not right, this code has no compiling error or warning.
Developer tool screenshot is under below if it helps.
This is the whole code,the wrong highlight color Snippet is in the last line.
#[allow(dead_code)]
enum List<T> {
Cons(T, Box<List<T>>),
Nil,
}
use List::{Cons,Nil};
#[allow(dead_code)]
impl<A: Copy> List<A> {
fn cons(x: A, xs: List<A>) -> List<A> {
Cons(x, Box::new(xs))
}
fn pure(x: A) -> List<A> {
List::cons(x, Nil)
}
fn fold_left<B>(&self, init: B, f: impl Fn(B, A) -> B) -> B {
match self {
Cons(item, ref rest) => rest.fold_left(f(init, *item), f),
Nil => init,
}
}
fn fold_right<B>(&self, init: B, f: impl Fn(A, B) -> B) -> B {
self.reverse().fold_left(init, |b, a| f(a, b))
}
fn reverse(&self) -> List<A> {
self.fold_left(Nil, |b, a| Cons(a, Box::new(b)))
}
fn concat(&self, right: List<A>) -> List<A> {
self.fold_right(right, |a, b| Cons(a, Box::new(b)))
}
fn map<B: Copy>(&self, f: impl Fn(A) -> B) -> List<B> {
self.fold_left(Nil, |b, a| Cons(f(a), Box::new(b)))
.reverse()
}
fn flat_map<B: Copy>(&self, f: impl Fn(A) -> List<B>) -> List<B> {
self.fold_right(Nil, |a, b| f(a).concat(b))
}
fn filter(&self, f: impl Fn(A) -> bool) -> List<A> {
self.flat_map(|x| if f(x) { List::pure(x) } else { Nil })
}
}