Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to write an if statement that tests two conditions in Groovy, but the language does not appear to support && or &. I'd like to avoid using a nested if statement if possible for this. How can I accomplish this?
Yes groove support the logical-and operator('&&') and bitwise-and operator('&').
class Example {
static void main(String[] args) {
// Initializing a local variable
int a = 2
//Check for the boolean condition
if (a<100 && a>0) {
//If the condition is true print the following statement
println("The value is less than 100");
} else {
//If the condition is false print the following statement
println("The value is greater than 100");
}
}
}
but it is not supporting '&&' or '&'
That's incorrect. Both the logical AND (&&) and the bitwise and (&) work in groovy. See the list of operators in the official documentation.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need call three API one after another in same view controller.these three API called after every 10 min. And the first api call's response use as parameter to third api call.
func a(){}
func b(){}
Func c(){}
Is there a way to call these api synchronously.
I want to call first func a then b and c.
How can i can implement the logic ? Thanks in advance.
Write three functions, call1(), call2(), and call3(). Have each one take a completion handler:
That might look something like this:
typealias networkCompletion = (Data) -> Void
func call1(callCompletion: networkCompletion) {
//set up a URLSessionDataTask in `myDataTask`
myDataTask.run() { result in
switch result
{
case success(data):
callCompletion(result.data)
}
case error:
//error handling
{
}
//And so on for call2 and call3...
//Then have the completion handler for call1 call call3,
//and the completion handler for call2 call call3:
call1() { call1Data in
call2(call1Data) { call2Data in
call3(call2Data) { call3Data in
//Call3 is complete. You've got your final data in call3Data
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How to get an object reference in Scala? I would like to compare those references to see if it's a new or old object which is being used.
var objArr: ArrayBuffer[someObj] = new ArrayBuffer[someObj](0)
// fill array
objArr(0) // how to get the internal reference of that array object and not the content of it?
Any help is highly appreciated!
Actually objArr(0) seems to be what you want
class MyClass
val x = new MyClass
var objArr: ArrayBuffer[MyClass] = ArrayBuffer(x)
objArr(0) eq x // true
objArr(0) eq new MyClass // false
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Came across this in a discussion on MONADs although a bit hard to follow. But the question is, I can get map and flatmap with Big Data, but the stuff here makes me feel very shaky. firstname => lastname, compounded =>, etc. Not getting it ... Who can explain? It works though.
val maybeFirstName = Option("Joe");
val maybeLastName = Option("Black");
val maybeFullName = maybeFirstName.flatMap { firstName =>
maybeLastName.map { lastName =>
firstName + " " + lastName
}
}
As with many compound operations, it sometimes makes sense to decipher it from the inside out.
maybeLastName.map(lastName => /*some op on lastName*/)
map() opens the Option and assigns the value, if it's there, to lastName. If the Option is None then there is no lastName and no operation on it. If the Option is not None then operation is performed and the result is re-wrapped into an Option.
flatMap() does the same thing except that it doesn't re-wrap the result. Instead the op inside is required to return a value already wrapped, i.e. an Option.
So, to review:
maybeFirstName.flatMap { firstName => //op on firstName must return Option
maybeLastName.map { lastName => //op on lastName should not return Option
/* op */
}
}
If either maybe...Name is None then the final result is None.
Map applies function on maybeLastName and retur Option or Option(Joe Black). So if you use map instead of flatMap, you get Option(Option(Joe Black)), because map always return new Option, so to remove inner option you need to use flatMap or combination map and flatten.
Here you can see how works flatten
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am trying to declare a var in which then I will set with some kind of class depending on a certain condition, so :
var tmodule
if..
tmodule=ModuleInput(frame: CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height))
if..
tmodule=ModuleOut(frame: CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height))
I get an error on the declaration , and I can't find the right way to do it.
tmodule=tmodule:ModuleInput=ModuleInput(frame: CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height))
This doesn't make any sense. Perhaps you meant:
var tmodule: ModuleInput //type annotation necessary here
//...
let frameSize = self.view.frame.size
tmodule = ModuleInput(frame: CGRectMake(0, 0, frameSize.width, frameSize.height)) //type inferred here
tmodule=tmodule:ModuleInput=ModuleInput(....
should be
tmodule = ModuleInput(....
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a class which declare the dictionary tags
This is declare in class FirstClass
-(NSDictionary *)getTags{
return tags;
}
At unit testing
i created FirstClassTest class of ocUnit Testing
included #import "FirstClass.h"
-(void)setUP{
[super setUp];
// Allocations the class
_firstClass = [[FirstClass alloc]init];
}
-(void)tearDown{
_firstClass =nil;
[super tearDown];
}
-(void)testDictationGetValue{
// Need to write Unit test for that class
[_firstClass getTags];
}
This is my first time writing unit testing!
Can any one guide me to write proper unit test cases
#All Thanks in advance
First, it looks like you’re writing a plain getter. That doesn’t make much sense in modern Objective-C: if you just want to return a pointer to an instance variable, use a synthesized getter (and drop the get prefix).
Second, what do you want to test here? If you just want to test that the getter really does return some dictionary, then the test is essentially useless. Maybe the tags are calculated according to some other values? Then set up those values and check that the tags dictionary is computed correctly. Never write test just for their own sake.
IT should be!!!
-(void)testDictationGetValue
{
_firstClass = nil;
_firstClass = [[FirstClass alloc] init];
NSDictionary *t_dictionary = [_firstClass getTags];
if (t_dictionary == nil) {
STAssertNil(nil, #"TestFailed return value is nil");
}
else {
STAssertNotNil(t_dictionary, #"Retrun value");
}
}