How to check if string is valid by checking if its value is in array - joi

joi.string().valid(['foo', 'bar']) has been deprecated.
Error: Method no longer accepts array arguments: allow
What is the new way of achieving this?

Using spread syntax works perfectly!
joi.string().valid(...['foo', 'bar'])

Related

Apache AGE - Creating Functions With Multiple Parameters

I was looking inside the create_vlabel function and noted that to get the graph_name and label_name it is used graph_name = PG_GETARG_NAME(0) and label_name = PG_GETARG_NAME(1). Since these two variables are also passed as parameters, I was thinking that, if I wanted to add one more parameter to this function, then I would need to use PG_GETARG_NAME(2) to get this parameter and use it in the function's logic. Is my assumption correct or do I need to do more tweaks to do this?
You are correct, but you also need to change the function signature in the "age--1.2.0.sql" file, updating the arguments:
CREATE FUNCTION ag_catalog.create_vlabel(graph_name name, label_name name, type new_argument)
RETURNS void
LANGUAGE c
AS 'MODULE_PATHNAME';
Note that all arguments come as a "Datum" struct, and PG_GETARG_NAME automatically converts it to a "Name" struct. If you need an argument as int32, for example, you should use PG_GETARG_INT32(index_of_the_argument), for strings, PG_GETARG_CSTRING(n), and so on.
Yes, your assumption is correct. If you want to add an additional parameter to the create_vlabel function in PostgreSQL, you can retrieve the value of the third argument using PG_GETARG_NAME(2). Keep in mind that you may need to make additional modifications to the function's logic to handle the new parameter correctly.
The answers given by Fahad Zaheer and Marco Souza are correct, but you can also create a Variadic function, with which you could have n number of arguments but one drawback is that you would have to check the type yourself. You can find more information here. You can also check many Apache Age functions made this way e.g agtype_to_int2.

How to sort an array filled with Timestamps?

I have a list where its elements are Timestamps in the form of
Timestamp(seconds=..., nanoseconds=...)
so I got
List myarr = [Timestamp(seconds=..., nanoseconds=...),Timestamp(seconds=..., nanoseconds=...),Timestamp(seconds=..., nanoseconds=...)]
How can I order this list? I have tried calling myarr.sort() but then I got the following error:
This expression has a type of 'void' so its value can't be used.
Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.
How can I sort the above mentioned array?
What is Timestamp? Is it perhaps firebase Timestamp?
Either way, it has to implement Comparable if it should be used without defining the sort method manually.
Otherwise you'll have to do myArr.sort((a,b) => "do your own sort")
For sort it in asc:
myarr.sort((a, b) => a.milliseconds - b.milliseconds);
For sort it desc
myarr.sort((a, b) => b.milliseconds - a.milliseconds);
Those are good answers, thank you. However, for me the following worked:
..sort()

How do I assert that an Option contains something in zio-test?

I tried
assert(anOption)(contains("x"))
But that only works for Iterables such as List or Seq.
assert(anOption)(isSome(equalTo("x")))
Could also be assert(anOption)(equalTo(Some("x"))) - just using equality. Or if you want to use contains: assert(isTrue(anOption.contains("x"))) using the contains operator on option

Spread syntax in function call in Reason

In Javascript you can use the spread syntax in a function call like this:
console.log(...[1,2,3]);
Is there an equivalent in Reason? I tried the following:
let bound = (number, lower, upper) => {
max(lower, min(upper, number));
};
let parameters = (1,0,20);
bound(...parameters) |> Js.log;
But this gives an unknown syntax error:
Try reason snippet
There's not. Reason is a statically typed language, and lists are dynamically-sized and homogenous. It would be of very limited use, and not at all obvious how it would deal with too few or too many arguments. If you want to pass a list, you should just accept a list and deal with it appropriately, as a separate function if desired.
You could of course use a tuple instead, which is fixed-size and heterogenous, but I don't see a use-case for that either, since you might as well just call the function directly then.
For JavaScript FFI there is however the bs.splice attribute, which will allow you to apply a variable number of arguments to a js function using an array. But it needs to be called with an array literal, not just any array.

FIRAuth.auth() compiling error: "Cannot use optional chaining on non optional value 'FIRAuth'"

Cannot use optional chaining on non optional value 'FIRAuth'
I have tested every solutions, but always got the same error.
Even if i create a new project, when i'm using FIRAuth, i always got a compiling error.
Can someone help me please. I use Swift 2, Xcode 7, IOS9
If you are trying to add FIRAuth.auth()? try to remove (?).
FIRAuth.auth() is non optional so treating them as one might result to the error “Cannot use optional chaining on non optional value 'FIRAuth'”
Optional chaining is a process for querying and calling properties,
methods, and subscripts on an optional that might currently be nil
Check Optional Chaining