ng : File C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 is not digitally signed. You cannot run
this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ng serve
+ ~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Run Code Online (Sandbox Code Playgroud)
在给 ng 服务时显示此错误..如何克服它?
我一直在寻找在Javadoc文档中的CharSequence接口,通过实施String
,StringBufer
和其他几个人,更具体的chars()
方法,而说的Javadoc
返回int的流,从此序列中对char值进行零扩展.
现在,我知道它返回int
值,并且int
可以转换为char
值.但"零延伸"是什么意思呢?
例如,这不是尾调用:
map _ [] = []
map f (x : xs) = f x : map f xs
Run Code Online (Sandbox Code Playgroud)
由(:)
数据构造函数保护的递归调用,因此它不会像其他语言中的等价物那样构建巨大的堆栈。它是这样工作的:
map (+1) (1 : 2 : 3 : [])
2 : map (+1) (2 : 3 : [])
2 : 3 : map (+1) (3 : [])
2 : 3 : 4 : map (+1) []
2 : 3 : 4 : []
Run Code Online (Sandbox Code Playgroud)
为什么不
map (+1) (1 : 2 : 3 : [])
2 : map (+1) (2 : …
Run Code Online (Sandbox Code Playgroud) recursion haskell functional-programming lazy-evaluation tailrecursion-modulo-cons
我有以下函数来统一多个集合(包括重复的元素):
public static <T> List<T> unify(Collection<T>... collections) {
return Arrays.stream(collections)
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
如果函数具有类似的集合交集(使用类型相等),那将是很好的.例如:
public static <T> List<T> intersect(Collection<T>... collections) {
//Here is where the magic happens
}
Run Code Online (Sandbox Code Playgroud)
我发现了交叉函数的一个实现,但它不使用流:
public static <T> Set<T> intersect(Collection<? extends Collection<T>> collections) {
Set<T> common = new LinkedHashSet<T>();
if (!collections.isEmpty()) {
Iterator<? extends Collection<T>> iterator = collections.iterator();
common.addAll(iterator.next());
while (iterator.hasNext()) {
common.retainAll(iterator.next());
}
}
return common;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法实现类似于使用流的统一函数?我在java8/stream api中没那么有经验,因为一些建议会非常有用.
我正在尝试使用Mockito创建一个从Mock对象返回的Mock对象.具体来说,我正在尝试模拟PlayerConnection
我的程序可以用来检索IP地址的对象.
你可以PlayerConnection object
在这里找到更多相关信息.它返回一个InetSocketAddress
然后InetAddress
可以返回一个可以返回String
与播放器的IP的a .但我无法走得那么远,因为我的第一次when(class.function()).thenReturn(returnVariable)
投掷了NullPointerException
.这是我的代码:
/**
* Creates a partial mock of a connection that can return an ip address.
*
* @param String
* The IP to return when the connection gets asked.
* @return
*/
private PlayerConnection newConnection(String ipString)
{
PlayerConnection playerConnection = mock(PlayerConnection.class);
InetSocketAddress inetSocketAddress = mock(InetSocketAddress.class);
InetAddress inetAddress = mock(InetAddress.class);
when(playerConnection.getAddress()).thenReturn(inetSocketAddress);
when(inetSocketAddress.getAddress()).thenReturn(inetAddress);
when(inetAddress.getHostAddress()).thenReturn(ipString);
return playerConnection;
}
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪,发生在when(playerConnection.getAddress()).thenReturn(inetSocketAddress)
:
Tests run: 1, …
Run Code Online (Sandbox Code Playgroud) 我想在我的项目中使用模板 Maven 插件,但我不知道把我的源代码放在哪里。插件文档指定:
${basedir}/src/main/java-templates
Run Code Online (Sandbox Code Playgroud)
但 Intellij 无法将其识别为源文件夹,因此不允许我在其中创建类。如果我手动将其设为源文件夹,则会遇到无法从该src/main/java
文件夹引用我的类的问题。
我应该把要过滤的类放在哪里,或者如何配置 Intellij 以使用模板插件?
假设我想要一个type函数[[a]] -> [[b]] -> [[(a, b)]]
。我敢肯定我能弄清楚,但是有可能,它不会像一样干净 zipWith zip
。
在Hoogle中输入这种类型签名可以为我提供一些功能,但这些功能来自leancheck
and extrapolate
包,我不想在没有充分理由的情况下将其拖到我的项目中。
鉴于您可以通过方程式推理来计算函数组成,我想知道是否与此过程相反:是否有一种方法可以“分解”复杂的类型签名并将其简化为最简单的函数组成?
我在这个难题中寻求一些方向,我需要将特定的最近邻居分组在一起。
我的输入数据是:
myList :: Map (Int, Int) Int
myList =
fromList
[((-2,-2),0),((-2,-1),0),((-2,0),2),((-2,1),0),((-2,2),0)
,((-1,-2),1),((-1,-1),3),((-1,0),0),((-1,1),0),((-1,2),1)
,((0,-2),0),((0,-1),0),((0,0),0),((0,1),0),((0,2),0)
,((1,-2),0),((1,-1),0),((1,0),0),((1,1),2),((1,2),1)
,((2,-2),0),((2,-1),2),((2,0),0),((2,1),0),((2,2),0)]
Run Code Online (Sandbox Code Playgroud)
这是这个 5 x 5 网格(棕色土地,蓝色水)的数据表示:
我使用
(Int,Int)
作为XY
坐标,因为必须生成列表的方式(因此其顺序)是在(0,0)
作为原点的笛卡尔坐标网格上的螺旋中。剩下的Int
就是人口规模0
,即水、1..9
土地。
由于我的排序,Map
我一直在努力寻找一种方法来遍历我的数据并返回4
分组的土地项目,这些土地项目由于彼此连接的接近度(包括对角线)而分组,所以我正在寻找如下结果:
[ [(-1 , 2)]
, [(1, 2),(1,1)]
, [(-2, -0),(-1,-1),(-1,-2)]
, [(2, -1)]]
Run Code Online (Sandbox Code Playgroud)
我研究并尝试了各种算法,如 BFS、Flood Fill,但我的输入数据永远不符合结构要求,或者我对主题的理解不允许我将其转换为使用坐标。
有没有办法可以直接在数据上运行算法,或者我应该寻找另一个方向?
很抱歉,到目前为止我还没有代码示例,但我什至无法创建任何远程有用的东西。
我是Java8和多线程工作的新手.我在下面尝试了这段代码
public class Test {
public static boolean bchanged = true;
public static void main(String[] args) {
new Thread(new Runnable() {
public void run() {
while (true) {
if (bchanged != bchanged) {
System.out.println("here");
}
}
}
}
).start();
new Thread((Runnable) () -> {
while (true) {
bchanged = !bchanged;
}
}).start();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,没有"here"的打印.但是,当我改变
public static volatile boolean bchanged = true;
Run Code Online (Sandbox Code Playgroud)
那么"这里"将被打印出来.
我原来的推论是,lambda将有一个boolean值的本地副本,当它不是volatile时它不会影响另一个线程,但当我尝试在两个线程中打印出boolean值时,它证明我是错误.所以我在这种情况下非常困惑,如何volatile
影响lambda的工作方式.
我使用流过滤器从请求对象中获取两个日期。在那里我必须比较这些对象,然后将它们收集到列表中。但现在我得到这个错误。请帮我解决。
错误:
类型不匹配:无法从 int 转换为 boolean
代码:
Date checkIn = req.getCheckIn();
Date checkOut = req.getCheckOut();
List<PlaceBook> filtered = checkInVal.stream().filter(string ->
string.getCheckInDt().compareTo(checkIn)).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud) java ×6
haskell ×3
java-8 ×3
java-stream ×2
algorithm ×1
angular ×1
collections ×1
hoogle ×1
lambda ×1
maven ×1
maven-plugin ×1
mockito ×1
recursion ×1
unit-testing ×1
volatile ×1