我之间的差异的理解List.fold,并List.foldBack为在其相反的顺序列表折返迭代.这两个函数都会累积列表中项目的结果.
我很难想出一个很好的例子,最好将foldBack放在列表上.在我提出的示例中,如果函数逻辑执行相同的操作,则fold和foldBack的结果相同.
[<Fact>]
let ``List.foldBack accumulating a value from the right to the left``() =
let list = [1..5]
let fFoldBack x acc =
acc - x
let fFold acc x =
acc - x
let foldBackResult = List.foldBack fFoldBack list 0
let foldResult = List.fold fFold 0 list
Assert.Equal( -15, foldBackResult ) // 0 - 5 - 4 - 3 - 2 - 1
Assert.Equal( -15, foldResult ) // 0 - 1 - 2 - …Run Code Online (Sandbox Code Playgroud) SaveChanges()在 Entity Framework Core 中,是否可以看到在调用方法时将应用的 SQL DbContext?
<router-outlet></router-outlet>我正在尝试在 Angular Material 弹出对话框中使用。但是,路由器出口部分不会呈现任何内容,也不会将任何内容记录到控制台。
如果我将 添加<router-outlet></router-outlet>到弹出对话框的组件(ContextBuyerPinComponent)的 HTML 内容中,那么它就可以正常工作。
路线如下:
const demoRoutes: Routes = [
{
path: 'demo',
children: [
{ path: 'register-email', component: RegisterEmailComponent },
{
path: 'context-buyer-pin',
component: ContextBuyerPinComponent,
children: [
{ path: 'services', component: ContextPinServicesComponent },
{ path: 'emails', component: ContextPinEmailsComponent },
{ path: 'details', component: ContextPinDetailsComponent }
]
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
该对话框是通过 ContextBuyerPinComponent 打开的,如下所示
this.matDialog.open(ContextBuyerPinDialogComponent, this.config);:
ContextBuyerPinDialogComponent HTML 如下:
const demoRoutes: Routes = [
{
path: 'demo',
children: [
{ path: 'register-email', …Run Code Online (Sandbox Code Playgroud) 我在一个案例中得到List.BinarySearch的奇怪结果.在列出"$ in"的列表中搜索"$ in"时,结果为-4.以下是一个突出问题的测试用例.只有寻找"$ in"的情况才会失败.
它可能是某种保留关键字吗?我编译了.Net Framworks 3.5,4.5.2和4.6,结果相同.
[TestMethod]
public void IssueWithBinarySearch() {
List<string> operators = new List<string>( new[] { "$eq", "$gt", "$gte", "$lt", "$lte", "$ne", "$in", "$nin" } );
Assert.AreEqual( 0, operators.BinarySearch( "$eq" ) );
Assert.AreEqual( 1, operators.BinarySearch( "$gt" ) );
Assert.AreEqual( 2, operators.BinarySearch( "$gte" ) );
Assert.AreEqual( 3, operators.BinarySearch( "$lt" ) );
Assert.AreEqual( 4, operators.BinarySearch( "$lte" ) );
Assert.AreEqual( 5, operators.BinarySearch( "$ne" ) );
Assert.AreEqual( 6, operators.BinarySearch( "$in" ) );
Assert.AreEqual( 7, operators.BinarySearch( "$nin" ) );
}
Run Code Online (Sandbox Code Playgroud)