• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 //! An example for `par_iter`
15 
16 use ylong_runtime::iter::prelude::*;
17 
main()18 fn main() {
19     let fut = async {
20         let sum = (1..30)
21             .collect::<Vec<usize>>()
22             .into_par_iter()
23             .map(fibbo)
24             .sum()
25             .await
26             .unwrap();
27         println!("{sum}");
28     };
29     ylong_runtime::block_on(fut);
30 }
31 
fibbo(n: usize) -> usize32 fn fibbo(n: usize) -> usize {
33     match n {
34         0 => 1,
35         1 => 1,
36         n => fibbo(n - 1) + fibbo(n - 2),
37     }
38 }
39