First argument passed to equalTo() cannot be an object - firebase

I try this code to get the events that their startdate equal to "Today":
`var ref = new Firebase("https://event-application.firebaseio.com/event");
$scope.evt=$firebaseArray(ref.child('event'));
var a= new Date();
ref.orderByChild("startdate").equalTo(a).on("child_added",function(snapshot){
console.log(snapshot.val() )
})`
But i get this error:
First argument passed to equalTo() cannot be an object

It happens because you are using a Date object.
Check the documentation:
equalTo()equalTo(value, [key])
Arguments
value String, Number, Null, Boolean
The value to match for. The argument type depends on which orderBy*() function was used in this query. Specify a value that matches the orderBy*() type. When used in combination with orderByKey(), the value must be a string.

Related

Kusto: Failed to cast argument to scalar constant when using countof()

I defined a UDF function in kusto:
.create-or-alter function with (docstring = 'abc', folder='udfs')
get_index_of(input:string, lookup:string)
{
countof(input, lookup)
}
Next, I am going to use it an a sample table and it does not work
datatable (Input:string, Lookup:string)
[
"text:1", ":"
]
| extend Result = get_index_of(Input, Lookup)
I get the error message:
countof(): failed to cast argument 2 to scalar constant
Do you have any idea what is wrong? Please note, that the function works, because a sample run return result:
print get_index_of('text', 'e')
1
as of this writing, the 2nd argument to countof() is expected to be a constant string literal (i.e., one that doesn't change based on row context)

Swiftui: how do you assign the value in a "String?" object to a "String" object?

Swiftui dictionaries have the feature that the value returned by using key access is always of type "optional". For example, a dictionary that has type String keys and type String values is tricky to access because each returned value is of type optional.
An obvious need is to assign x=myDictionary[key] where you are trying to get the String of the dictionary "value" into the String variable x.
Well this is tricky because the String value is always returned as an Optional String, usually identified as type String?.
So how is it possible to convert the String?-type value returned by the dictionary access into a plain String-type that can be assigned to a plain String-type variable?
I guess the problem is that there is no way to know for sure that there exists a dictionary value for the key. The key used to access the dictionary could be anything so somehow you have to deal with that.
As described in #jnpdx answer to this SO question (How do you assign a String?-type object to a String-type variable?), there are at least three ways to convert a String? to a String:
import SwiftUI
var x: Double? = 6.0
var a = 2.0
if x != nil {
a = x!
}
if let b = x {
a = x!
}
a = x ?? 0.0
Two key concepts:
Check the optional to see if it is nil
if the optional is not equal to nil, then go ahead
In the first method above, "if x != nil" explicitly checks to make sure x is not nil be fore the closure is executed.
In the second method above, "if let a = b" will execute the closure as long as b is not equal to nil.
In the third method above, the "nil-coalescing" operator ?? is employed. If x=nil, then the default value after ?? is assigned to a.
The above code will run in a playground.
Besides the three methods above, there is at least one other method using "guard let" but I am uncertain of the syntax.
I believe that the three above methods also apply to variables other than String? and String.

xquery to check if the value is null then return null as string

I am new to XQuery. Please guide me to solve the issue below I want to return the null value as a string, if the below expression does not give any value.
Currently, the output doesn't show the 'name' field itself. I want to have a name with null. for eg-
if (IsNull(expression),null,expression)
$output.dataAccessResponse[1]/*:row/*:name/text()
You could use the fn:exists() function to test whether or not there is a text() node.
exists($output.dataAccessResponse[1]/:row/:name/text())
You could also use the fn:boolean() function to test the effective boolean value of the node.
boolean($output.dataAccessResponse[1]/:row/:name/text())
If you wanted to test whether or not there was a significant value i.e. something other than whitespace, you can fn:normalize-space() in a predicate, to ensure that only text() nodes that have meaningful text are selected, and then test fn:exists().
exists($output.dataAccessResponse[1]/:row/:name/text()[normalize-space()])
XQuery doesn't have null, so if you are asking what to return to indicate null, then you would want to return an empty sequence () instead of null.
So, you could execute something like this:
let $name := $output.dataAccessResponse[1]/:row/:name/text()
return
if (fn:exists($name))
then $name
else ()
But at that point, it's really the same as just attempting to select the text() with that XPath and it will either return the text() node or an empty sequence:
$output.dataAccessResponse[1]/:row/:name/text()

What is the syntax for defining a type when parameter has a default value?

How do I define the type of the config parameter given that it has a default value?
function (config = {}) {};
function f(config: Object = {}) {}
Or, more generally:
function f(p: T = v) {}
where T is a type, and v is a value of type T.
Interestingly, the type of function f is (p?: T): void. That is, Flow understands that providing a default value makes the parameter optional. You don't need to explicitly make the parameter type optional—although it doesn't hurt.
When writing declare function statement in a .js.flow file, you can't include the default value; it will cause an error. So you must explicitly declare that the parameter is optional:
declare function f(p?: T): void;
Flow types and default arguments in fat-arrow functions work similarly.
Given a function called foo which takes argument bar, you specify the type immediately after the argument with a colon, and then set its default value with the assignment (=) operator. Finally, immediately after closing the parentheses, you define the return value's type with another colon.
foo = (bar: string = 'baz'): string => bar;
foo(); // 'baz'

Cannot convert method group to non-delegate type

var deletedItems = tmpData.FindAll(qr => (Int32)qr.YearQuarter < (Int32)useDate.YearQuarter);'
userdate.yearquarter is
<Extension()>
Public Function YearQuarter(currentDate As Date) As Integer
Return Library.Dates.ToYearQuarter(currentDate)
End Function
I am getting an error here:
"< (Int32)useDate.YearQuarter;"
You are not calling YearQuarter correctly; you need to do YearQuarter(DateObject). Without the parens, you are trying to pass the method group that represents the function - not the return value of the function.

Resources