z****e 发帖数: 54598 | 1 没有回答到点子上啊
反正debug就是debug到这么一大坨出了问题
Stream.of(collect).filter(l -> l.size() > nums.size() / 2).collect(
Collectors.toList()).forEach(l -> System.out.println(l));
这里面n步,用fp的写法,ide都帮不了你啊
debug颇为耗时的说
上面scala的写法也是一样的
只不过没出问题,等出了问题的时候
这么一大坨还不如重构 |
|
z****e 发帖数: 54598 | 2 Stream.of(collect)
.filter(l -> l.size() > nums.size() / 2)
.collect(Collectors.toList())
.forEach(l -> System.out.println(l));
写成这样,然后设置断点,用ide一个个看过去
看哪一步出了问题 |
|
b**l 发帖数: 25 | 3 This will work:
List nums = new ArrayList<>();
for (int i = 1; i <= 15; i++) {
nums.add(1);
}
for (int i = 1; i <= 3; i++) {
nums.add(i);
}
Collection> collect = nums.stream().collect(Collectors
.groupingBy(n -> n)).values();
System.out.println(collect);
collect.stream().filter(l -> l.size() > nums.size() / 2)
.flatMap(Collection::stream).distinct()
.forEach(System.out::... 阅读全帖 |
|
w**2 发帖数: 724 | 4 so i have a code like this,
foreach my $row (@lines)
{
my ($v1, $v2) = @$row;
# a lot of logics here
print $v1." ---- ".$v2."n";
}
for whatever reason, i want to reuse this piece of code for different places
,
say i have 5 lines, how to make my function return 2D array like this ?
{(1,1), (2,2), (3,3), (4,4), (5,5)}
Thanks ! |
|
r**m 发帖数: 1825 | 5 http://www.yinwang.org/blog-cn/2015/03/03/how-to-respect-a-prog
怎样尊重一个程序员
得知一位久违的同学来到了旧金山湾区,然而我见到他时,这人正处于一生中最痛苦的
时期。他告诉我,自己任职的公司在他加入之前和之后,判若两人。录取的时候公司对
他说,我们对你在实习期间的表现和学术背景非常满意,你不用面试,甚至不用毕业拿
学位,直接就可以加入我们公司成为正式员工。然而短短一年后的今天,这位同学已经
完全感觉不到公司对自己技能的尊重。Manager让他做一些乱七八糟没技术含量的事情
,还抱怨说他做事太慢,并且在他的evaluation上很是写了一笔。在人格尊严和工作安
全感的双重打击之下,这位同学压力非常大,周末经常偷偷地加班,仍然无法让
manager满意。
我很了解这位同学的能力,在任何一流公司任职,肯定是绰绰有余了。他的名字我当然
保密,然而他所任职的公司因为太过嚣张,我不得不直接指出来——这就是被很多人向
往得像天堂一样的地方,Google。这位同学所描述的遭遇,跟我几年前在Google的实习
经历如出一辙。我仍然记得,G... 阅读全帖 |
|
d******e 发帖数: 2265 | 6 implicit class,大多数oop这种玩意。
string.decodeItemId能让大多数java程序员疯掉
其实 ParamaterHandler.getdecodeItemId(string)真的没复杂多少。
另外,foreach map组合 qxc疯了吧。其实你换成python generator, for loop和
coroutine做数据pipeline也不差多少。但是大多数程序员可以很快掌握,至少不那么抗拒 |
|
p*****2 发帖数: 21240 | 7
抗拒
现在java8也是map,foreach这些了,有什么可怕的?
implicit class是想模仿type class,有些时候很有用。
oop你指的是什么? |
|
l******9 发帖数: 579 | 8 【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: delete sheets from Excel workbook in C#
发信站: BBS 未名空间站 (Fri May 22 14:08:38 2015, 美东)
I need to delete some sheets from an Excel workbook in C#.
But, my code does not work.
// **aDeleteList** hold the sheets that need to be deleted from the
workbook wbk
static void delete_sht(ref MsExcel.Workbook wbk, List
aDeleteList)
{
MsExcel.Sheets my_st = wbk.Sheets;
foreach (MsExcel.Worksheet s in ... 阅读全帖 |
|
n*****t 发帖数: 22014 | 9 select where testname in (...)
或者 async.foreach |
|
n****j 发帖数: 1708 | 10 SQL 没法给你这样的结果,只能是 table,select * from table where testname in
(n1,n2, ...) order by testname,然后在 node 里 foreach row , result[testname
].push({func,time}) |
|
i**i 发帖数: 1500 | 11 1 没必要用啥库了。
2 要判断tree遍历结束。
随便写了一个:
var treeBuilder = (function () {
var count = 0;
var tree = {};
return {
setRoot: function (root) {
tree[root] = {};
this.grow(tree[root], root);
return this;
},
onDone: function (cb) {
this._cb = cb;
return this;
},
grow: function (root, branch) {
console.log("add: " + branch);
var self = this;
count++;
f... 阅读全帖 |
|
p*****2 发帖数: 21240 | 12
scala不是。scala没有yield就是foreach,加了yield就是map,语法糖而已 |
|
l****r 发帖数: 105 | 13 最近没事刷刷leetcode,碰到几个二叉树问题,测试时创建二叉树手写起来太麻烦(C#
),所以想自己搞个工具,作用是根据给定数组创建二叉树。
初步写出来是这样的:
public static TreeNode CreateBinaryTree(int[] values)
{
TreeNode root = new TreeNode(values[0]);
Queue nodeQueue = new Queue();
nodeQueue.Enqueue(root);
TreeNode current = null;
foreach (var value in values.Skip(1))
{
if (current == null || (current.left != null && current.
right != null))
... 阅读全帖 |
|
d****n 发帖数: 1637 | 14 Notable changes
This list of changes is relative to the last io.js v3.x branch release, v3.3
.0. Please see the list of notable changes in the v3.x, v2.x and v1.x
releases compiled in unified CHANGELOG for a more complete list of changes
from 0.12.x. Note, that some changes in the v3.x series as well as major
breaking changes in this release constitute changes required for full
convergence of the Node.js and io.js projects.
child_process: ChildProcess.prototype.send() and process.send() operate
... 阅读全帖 |
|
j**********3 发帖数: 3211 | 15 groovy能节省很多代码。好像foreach loop的功能也比较强大。可以动态的造代码。
别的就不造了。。 |
|
S***k 发帖数: 370 | 16 java's lambda is not nice and "nature" as c#.
if using java, it could looks like:
values.Stream()
.map(d->d*d)
.collect(Collectors.toList())
to be honest, I don't think this is better than for loop from any aspects.
The parallel is another funny one.
in c#, we just say Parallel.ForEach(value, v=>{blalala});
in java: values.parallelStream().map(blah).flatMap(List::Stream)
And, c# async is easier to use than java. I am still not sure if java's
async could work well because it is implemented using... 阅读全帖 |
|
z****e 发帖数: 54598 | 17 all u need is rxjava
then u can do sth. like .map(d -> d*d)
and forEach(v->{blablabla});
this is just a way to pass in function as a parameter
how stupid u r to think this is impossible for java
u can even impl. this by urself rather than using rxjava
as long as u have lambda & reflection
besides, for async part, u should know java.nio
which have been impl.ed in 1.4 many years ago
if u wanna a sync way to write async code
u need javaagent and for framework quosar would be the answer |
|
z****e 发帖数: 54598 | 18 compared to for loop
how to use for loop in the streaming?
u dont even know the border of the stream/loop
u need a listener rather than a loop
reactive rather than active
reactive is not for zhuangbi
is used for solving problems
especially for those streaming industry like Netflix
if u can use for loop then plez use for loop
do not use forEach which should only be used in streaming api
and i personally believe for loop is enough for batch api
u dont need streaming for batch like db/file system c... 阅读全帖 |
|
a******n 发帖数: 5925 | 19 来自主题: Programming版 - 今晚还编程 Lol
赞forEach |
|
l**********n 发帖数: 8443 | 20 ip.toLong = function(ip) {
var ipl = 0;
ip.split('.').forEach(function(octet) {
ipl <<= 8;
ipl += parseInt(octet);
});
return(ipl >>> 0);
};
ip.fromLong = function(ipl) {
return ((ipl >>> 24) + '.' +
(ipl >> 16 & 255) + '.' +
(ipl >> 8 & 255) + '.' +
(ipl & 255) );
}; |
|
发帖数: 1 | 21 R的并行计算挺方便的,parallel,doparallel,foreach
有些库自身就提供并行化计算,比如forecast,caret
apply系列并不真的并行化,只是写code简介
vectorization有一定帮助,但是不解决根本问题
最终要想性能上去还是要用c/c++写库然后wrap
R的最大优势就是几乎所有最新的统计算法都能第一时间登陆这个平台
R唯一的缺憾是只能内存操作,但是现在也有大数据平台的接口和用硬盘做swap的库
另一个之前的午后是深度学习库,现在mxnet有Amazon撑腰了,而且对R的支持还不错。 |
|
m****o 发帖数: 182 | 22 rxjava需要实现多线程处理的话,需要把每个操作flatmap到一个observable上去,然
后subscribeOn一个scheduler,你的情况可以直接上库自带的computational
scheduler。注意flatmap是不考虑输入输出顺序统一的,这一点很其他主流fp库设计不
同容易搞错。如果需要输入输出顺序统一,需要用concatmap。
另外好像你不是很在乎使用全局线程池,那样的话可以直接用前面有人提到的java8原
生的parallelMap。
val in = new BufferedReader(new InputStreamReader(System.in))
try {
val stream = in.lines()
try stream.parallelMap(data => ???).filter(data => ???).forEach{/* here is
your sink */}
finally stream.close()
}
finally {
in.close()
} |
|
o*****s 发帖数: 39 | 23 完全不懂perl,有人帮我写了一个程序,但是现在要改一点。
任务:从一个网页上抓取一个关键词后面的field。原来都是在同一行的,现在有些网
页变成了下一行或者空行后的下一行。所以现在任务就是从一个网页上抓取一个关键词
TYPE OF REPORTING PERSON:后的第一个非空field,无论在哪一行。原句是:
foreach $line (@contents) {
if (($_,$entry) = ($line =~ m/(TYPE OF REPORTING PERSON:[\s]
+)([0-9]*)/)) {
print OUTF $address,"\t",$entry,"\t";
last;
怎么改?谢谢谢谢!大包子伺候 |
|
h******a 发帖数: 198 | 24 now I could only think up one way:
foreach file(*.cpp)
mv $file `basename $file .cpp`.C
end
for tcsh/csh |
|
G**T 发帖数: 388 | 25 I have many PCT files, f01.pct, f02.pct.....
1)I need use ihdr2sun transfer it to f01.ras, f02.ras.....
2)then use convert transfer f01.ras, f02.ras...
to f01.jpg, f02.jpg.....
how can I do this?
I know 1)
foreach file (`ls *.pct')
ihdr2sun $file
end
but I do not know how to finish 2)
I'm not familar with UNIX
thx |
|
r***r 发帖数: 25 | 26
or if ur unix doesn't hv it (i think all solaris hv this command)
u can use a simple perl script.
#!/usr/local/bin/perl
require "flush.pl";
$TMP_FILE = "/tmp/dos2unix.tmp";
foreach $f (@ARGV) {
if ( -f $f) {
print "Processing $f ..."; &flush( STDOUT);
open( OUT, "> $TMP_FILE") || die "Cannot open tmp file for writing\n";
open( IN, "< $f") || die "Cannot open tmp file for reading\n";
while( $line = ) {
$l = length( $line);
if ( ( $l |
|
i*******n 发帖数: 166 | 27 #!/bin/tcsh
foreach i (data*.dat)
mv $i my$i'a'
end |
|
i*******n 发帖数: 166 | 28 #!/bin/tcsh -f
foreach i (*)
sed 's/data[1-9]\.dat/my&a/g' $i > outtmp
mv -f outtmp $i
end |
|
X****r 发帖数: 3557 | 29 I usually use this, but I bet there's a better way doing so
(assuming tcsh)
foreach file ( sige* )
mv $file `echo $file | cut -c -4`.`echo $file | cut -c 5-`
end |
|
t******q 发帖数: 117 | 30 foreach file `find . -type f -print`
chmod 744 $file
end
somthing like this, not test |
|
b*********l 发帖数: 30 | 31 Write a CGI script using perl -- so you can run it thru the web, the block of
code for deleting the files can be like
$basedir=...
$datadir=...
...
if ($FORM{'action'} eq 'remove') {
@files=glob("$basedir/$datadir/*.*");
foreach $file (@files)
{
$fn=$file;
unlink ("$file");
print "$fn has been deleted. ";
}
#...
} |
|
h*****t 发帖数: 40 | 32 Yes, I did run from web browser
the results is:
blah blah blah
...
whoami = "my username"
I am sorry for my native Question.
environ.cgi
#! /usr/local/bin/perl
printf "Content-type: text/html\n\n";
printf " environ.cgi \n";
printf "Query Results";
printf "You submitted the following %%ENV pairs:\n \n";
foreach $item (sort(keys %ENV))
{ printf "- CGI variable : %s Value : %s
\n", $item, $ENV{$item};
}
printf " \n";
printf "w |
|
t*******l 发帖数: 421 | 33 比如在每个目录里有个子目录,其中包括一个文件含有我需要的信息。
$ ls
dir1 dir2 dir3
$ ls dir1
file1
$ more file1
user name: mary england
$ ls dir2
file2
$ more file2
user name: jon hotland
... ...
如果我想写个script,运行后会从第一到第三个目录自动找到user name,
用foreach file (*)语句后,却只读了第一个dir1,没有接着做dir2,dir3.
请帮我提示一下。多谢。 |
|
c*****e 发帖数: 32 | 34 "ls -l" shouldn't be working for sure, coz with '-l' the output will mess your
things up.
gotta be:
foreach my $file (`ls`){
#print "open FH, $file\n";
open (FH, $file) || die "can not open $file";
....... #your code goes here
.......
close (FH);
}
work. |
|
f****y 发帖数: 70 | 35 有谁解释一下:
use Net::Telnet::Cisco;
my $session1 = Net::Telnet::Cisco->new(Host => '111.157.143.5');
$session1->login('', 'ciscophee');
@shver1 = $session1->enable('pheecisco');
@shver1 = $session1->cmd('clear crypto isakmp');
@shver1 = $session1->cmd('clear crypto sa');
$session1->close;
foreach $line (@shver1){
print "$line";
}
是重起cisco router?
除了perl,还有其他方法可以实现吗?(远程操作cisco router) |
|
a****y 发帖数: 1035 | 36 #!/bin/csh
foreach fn (*)
grep 'aaa' $fn >/dev/null
if ($status == 0) then
cp $fn /newdir
endif
end |
|
z*****u 发帖数: 12 | 37 sorry i should not have said that...
perl's philosophy is that "there's always a better way to do it..." and of
course, there's always people who know better way to do it. you are absolutely
in the right perl thinking mode. :)
if the file is not too big, i would do this
while(<>) {
foreach $word (split) {
if ($word =~ /^cbo-[0-9]*$/i) {
push @cbo_strings, $word;
}
}
}
print @cbo_strings;
#share with us if you have better idea...
go |
|
k**e 发帖数: 86 | 38 参考书"Programming Perl" 有这样一段程序,参2.7.2节 "Passing References",哪位
大侠能解释一下那个“return”语句。实在是有些糊涂,总觉得“$seen{$_} == @_”永
远是FALSE,这样, inter能返回有效的list么?
@common = inter( \%foo, \%bar, \%joe );
sub inter {
my ($k, $href, %seen); # locals
foreach $href (@_) {
while ( ($k) = each %$href ) {
$seen{$k}++;
}
}
return grep { $seen{$_} == @_ } keys %seen;
} |
|
c**o 发帖数: 166 | 39 On Solaris system, I want to install some packages at one time.
For example, I have some packages in a directory. Now I want to install them
all at one time. Usually I just use
foreach i (`ls`)
pkgadd -d $i
end
from csh.
Of course, I have to answer all kinds of questions there.
I also tried to use an admin file or -n option. But I still got
Select package(s) you wish to process ('all' to process all packages)
(default: all) [?,??,q]:
then it would not proceed until I press ENTER.
There should be |
|
b***t 发帖数: 1104 | 40 foreach $k (sort keys %hash) {
print "$k => $hash{$k}\n";
} |
|
b***t 发帖数: 1104 | 41 foreach $value (sort { $h{$a} <=> $h{$b} } keys %h) {
print "$value => $h{$value}\n";
} |
|
a*****j 发帖数: 13 | 42 【 以下文字转载自 Linux 讨论区 】
【 原文由 AgehaDJ 所发表 】
for example,
if you want to find files that contain both "linux" and "unix",
so we should do it in shell
foreach(`grep -l "linux" *.*`)
grep "unix";
is it correct? or not?
or how should I do it? |
|
z********0 发帖数: 9013 | 43 oh csh
I'm not familiar with csh
hope it works:
#!/bin/csh
foreach line ("`cat myemailfile`")
mail $line < message.txt
end |
|
N****O 发帖数: 4202 | 44 用C-shell script...
我有一堆email address在一个address.txt里。怎么才能让这个script file reads
from address.txt, and sends the message in another file (eg.text.txt) to
every email address呢?
应该是用cat,set,foreach之类的command.
我知道发给一个email address是:mail [email protected]
/* */ < text.txt
谢谢! |
|
z********0 发帖数: 9013 | 45 oh csh
I'm not familiar with csh
hope it works:
#!/bin/csh
foreach line ("`cat myemailfile`")
mail $line < message.txt
end |
|
l******9 发帖数: 579 | 46 【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: delete sheets from Excel workbook in C#
发信站: BBS 未名空间站 (Fri May 22 14:08:38 2015, 美东)
I need to delete some sheets from an Excel workbook in C#.
But, my code does not work.
// **aDeleteList** hold the sheets that need to be deleted from the
workbook wbk
static void delete_sht(ref MsExcel.Workbook wbk, List
aDeleteList)
{
MsExcel.Sheets my_st = wbk.Sheets;
foreach (MsExcel.Worksheet s in ... 阅读全帖 |
|
|
x*****w 发帖数: 8 | 48 line()=0
foreach Mesh
for i=1,3
line(node1,node2)++
endfor
endfor
if(line<2) line is boundary
connect all line seg |
|
x*****w 发帖数: 8 | 49 line()=0
foreach Mesh
for i=1,3
line(node1,node2)++
endfor
endfor
if(line<2) line is boundary
connect all line seg |
|
t*****e 发帖数: 224 | 50 ☆─────────────────────────────────────☆
tapioca (sarah) 于 (Sun Mar 25 02:14:04 2007) 提到:
有N多个data file names,都以同一个字母开头,比如a1.dta, a2.dta,...a100.dta;
不知道有没有什么shortcut可以represent所有这些file.我知道如果是这么多个
variable,可以用a*代替,但用于data file,我试了不行...请高手指教!!万分感谢!
!
☆─────────────────────────────────────☆
wangxiaofei (Flying Fly) 于 (Sun Mar 25 15:06:43 2007) 提到:
I'd use a macro..
foreach num of numlist 1/100 {
.... using a`num'
...
}
☆─────────────────────────────────────☆
gadfly (Libran) 于 (Sun Mar |
|