有没有办法将这些功能组合在一起?
data Patient = Patient
{ name :: Name,
sex :: Sex,
age :: Int,
height :: Int,
weight :: Int,
bloodType :: BloodType
}
canDonate :: BloodType -> BloodType -> Bool
canDonateTo :: Patient -> Patient -> Bool
目前我只是手动应用它们
canDonateTo :: Patient -> Patient -> Bool
canDonateTo x y = canDonate (bloodType x) (bloodType y)
但是,我想知道是否有更好的方法来做到这一点。
答案 0 :(得分:9)
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws Exception {
// these commands work
run("/bin/sh", "-c", "echo $PATH");
run("/bin/bash", "-c", "echo $PATH");
run("/bin/zsh", "-c", "echo $PATH");
// these commands all work when I run them manually in a terminal
// but fail here with "zsh:1: command not found: ..."
run("/bin/zsh", "-c", "node -v");
run("/bin/zsh", "-c", "npm -v");
}
private static void run(String... command) throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.redirectErrorStream(true);
processBuilder.command(command);
Process process = processBuilder.start();
try(BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
for(String line = br.readLine(); line != null; line = br.readLine()) {
System.out.println(line);
}
}
System.out.println("return value: " + process.waitFor());
}
}
(基本上,您的方法只是内联了 /usr/bin:/bin:/usr/sbin:/sbin
return value: 0
/usr/bin:/bin:/usr/sbin:/sbin
return value: 0
/usr/bin:/bin:/usr/sbin:/sbin
return value: 0
zsh:1: command not found: node
return value: 127
zsh:1: command not found: npm
return value: 127
的定义,可以将其定义为
@types/react-color@2.17.5
)