编辑:
package com.demo;
// --
// imports for output
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
// --
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Demo {
@Getter
@RequiredArgsConstructor
public static class Keys {
private final String key1;
private final String key2;
}
public static void main(String[] args) throws JsonProcessingException {
//List1
List<String> list1 = Arrays.asList("A", "B", "C");
//List2
List<Keys> list2 = Arrays.asList(
new Keys("obj1", "A"),
new Keys("obj2", "B"),
new Keys("obj3", "D"),
new Keys("obj4", "F")
);
List<Keys> filteredList =
//create sequential stream over the elements of list2
list2.stream()
//filter using lambda
.filter(
//x - element of type Keys
x
->
//predicate returns true - if list1 contains key2 value of stream element
list1.contains(x.key2)
)
//collect stream to list
.collect(
//default list collector
Collectors.toList()
);
//output with pretty printer
ObjectWriter objectWriter = new ObjectMapper().writerWithDefaultPrettyPrinter();
System.out.println(objectWriter.writeValueAsString(filteredList));
}
}
输出示例:
[ {
"key1" : "obj1",
"key2" : "A"
}, {
"key1" : "obj2",
"key2" : "B"
} ]
您可以通过以下代码来实现这一点:
const filtered_people = people.filter(function(person){
return id_filter.includes(person.id) && person.gender === 'm';
});
只要确保每个人的ID是整数而不是字符串,就如您的示例。否则,Incluber()函数将无法匹配。另外,您的人
数组存在内部语法问题。因此,最终代码看起来像这样:
const people = [
{id: 1, name: "abc", gender: "m", age:15},
{id: 2, name: "a", gender: "m", age: 25},
{id: 3, name: "efg", gender: "f", age: 5},
{id: 4, name: "hjk", gender: "f", age: 35},
{id: 5, name: "ikly", gender: "m", age: 41},
{id: 6, name: "ert", gender: "f", age: 30},
{id: 7, name: "qwe", gender: "f", age: 31},
{id: 8, name: "bdd", gender: "m", age: 78}
]
const id_filter = [1,4,5,8]
const filtered_people = people.filter((person) => id_filter.includes(person.id) && person.gender === 'm')
console.log(filtered_people)
我希望这对您有帮助。
祝你好运。
基于上一个答案中的脚本,但是在测试它之后,该单元格被填充了文本。
我已经修改了if语句以仅允许该单元为空时的公式:
function Week1IFBlankFormulas() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange("D6").activate();
if (spreadsheet.getCurrentCell().isBlank()) {
spreadsheet.getCurrentCell().setFormula('=iferror(filter(Directors!$A$3:$A$55,Directors!D$4:D$56=$A5),)');
spreadsheet.getActiveRange().autoFill(spreadsheet.getRange("D6"), SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
} else {
return;
}
};
有趣的问题。在这种情况下,值2
将是SYCL内核中指令中的字面意义 - 我认为这是尽可能高的效率!您有一个轻微的并发症,您将隐式铸件从int
到float
。我的猜测是,您可能会在设备组装中以float
文字 2.0 。您的SYCL设备不必在运行时或类似的东西中从内存或铸造中获取该2,它只是存在于说明中。
同样,如果您有:
constexpr int c = 2;
// the rest of your code
[=](id<1> i) { inA[i] = inA[i] + c; }
// etc
编译器几乎可以肯定足够聪明,可以将c
的常数值传播到内核代码中。因此,同样,2.0
字面的说明最终出现在说明中。
我用DPC ++编制了您的示例,并提取了LLVM IR,并找到了以下行:
%5 = load float, float addrspace(4)* %arrayidx.ascast.i.i, align 4, !tbaa !17
%add.i = fadd float %5, 2.000000e+00
store float %add.i, float addrspace(4)* %arrayidx.ascast.i.i, align 4, !tbaa !17
这显示了float Load&amp;在同一地址存储/从同一地址存储,并在两者之间使用“添加2.0”指令。如果我修改以使用我所展示的变量c
,则获得相同的LLVM IR。
结论:您已经达到了最大的效率,并且编译器很聪明!
很长一段时间后,解决了错误,可以注意到路由器类逻辑有点更改了
@Slf4j
@Service
@AllArgsConstructor
public class MyService {
final CamelContext context;
@PostConstruct
public void consumerData() {
var rCamel = CamelReactiveStreams.get(context);
var numbers = rCamel.fromStream("numbers", Integer.class);
Flux.from(numbers).subscribe(e -> log.info("{}", e));
}
}
@Component
@NoArgsConstructor
public class MyRouter extends RouteBuilder {
// Injects the Subscriber
@Autowired MyService service;
@Override
public void configure() {
//onException(ReactiveStreamsNoActiveSubscriptionsException.class)
// .continued(true);
from("timer://reactiveApp?fixedRate=true&period=2s")
.transform(method(Random.class, "nextInt(100)"))
//.log("${body}");
.to("direct:message");
from("direct:message")
//.log("${body}")
.to("reactive-streams:numbers");
}
}
这样的导入:
const ipfsClient = require('ipfs-http-client');
然后创建连接:
const ipfs = ipfsclient.create(
https://ipfs.infura.io:5001 );
上传:
const uploadfile =等待ipfs.add({content:file});
您需要导入要在材料组件中使用的主题。
例如,您可以
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
用于全局CSS。
也有一次问题。 - &gt; Angular 5材料2:datePickerStyle
更多关于预建立主题的信息更多信息 - &gt; https://v6.material.angular.angular.angular.io/指南/主题#used-a-pre-built-theme
使用Mongoose 6.4
我通过删除_id:false
架构类型选项来解决此问题。
并从响应中删除_id,而不必用_。motit() s或 delete> delete 到处我在模式中添加了以下模式类型选项:
toObject: {
virtuals: true,
transform(doc, ret) {
delete ret._id
},
},
现在真正的问题是,为什么在服务器端生成ID时,简单地添加选项_id:false
会导致猫鼬错误没有猫鼬的帮助?
错误:MongooseError:文档在保存之前必须具有_id
.../node_modules/mongoose/lib/model.js:291:18
我部分回答了我自己的问题,但是为此,我真的不知道。
仅假设
select distinct
case when inp = 1 then gid
when inp = 2 then pid
when inp = 3 then did
end new_id,
case when inp = 1 then gname
when inp = 2 then pname
when inp = 3 then name
end as name
from final
order by 2
这是您想要的吗?
每个章节分批,然后是所有单词的数组,这些单词被1000个单词隔开。因此,要访问第一千字,它将是batch [0] [0]
。第3章,5000-5999单词 - 批次[2] [4]
。
batch=[]
for text in chapters:
print(text)
text = text.split()
n = 1000
batch.append([' '.join(text[i:i+n]) for i in range(0,len(text),n)])
您正在定义两个不同的变量,称为
用户名
,其中第一个是在main()
方法中定义的,而另一个位于while
方法代码>循环。访问变量时,DART将从您所处的范围中搜索它,然后将搜索扩展到外部范围,如果它找不到变量。但是
使用的表达式
在确定循环时应继续,无法访问循环中定义的范围。因此,它看到了第一个用户名
main()
中定义的变量。因此,问题在于,当您使用
var
时,您告诉DART,它应该定义一个新变量而不是使用现有变量。因此,代替:
您应该只执行以下操作以参考称为
用户名
的现有变量:You are defining two different variables called
userName
where the first are defined inside themain()
method while the other are inside the scope of thewhile()
loop.When accessing a variable, Dart will search for it from the scope where you are and then widen the search to outer scopes if it does not find the variable. But the expression used by
while
when determining of the loop should continue, cannot access the scope defined inside the loop. So it sees the firstuserName
variable defined inmain()
.So the problem is that when you use
var
, you are telling Dart that it should define a new variable instead of using an existing one.So instead of:
You should just do the following to refer to the existing variable called
userName
:Dart False首次运行正常,但是如果我再次运行代码并以真实的方式开始,即使我输入false