ios picker multi dimensional array - arraylist

pickerData = [[["A"], ["i","ii","iii"]],[["B"],["iv","v","vi","vii"]]]
}
Error: Contextual type 'String' cannot be used with array literal
Please advice how to use the array

Heterogenous literal collection types must be annoated:
Try this:
let pickerData: [[[String]]] =
[
[
["A"],
["i","ii","iii"]
],
[
["B"],
["iv","v","vi","vii"]
]
]

Related

Karate json key list variable assignment

New to Karate, and JSON, for that matter, but I've got a variable like:
response {
entries {
products [
{
names [
"Peter Parker",
"Tony Stark",
"Captain America"
]
},
{
names [
"Thomas Tinker",
"Jimmy Johnson",
"Mama Martha"
]
}
]
}
}
match each response.entries.products[*].names returns a list like:
["Peter Parker","Tony Stark","Captain America","Thomas Tinker","Jimmy Johnson","Mama Martha"]
But I'd like to assign that output to a variable, such as:
* def variable = response.entries.products[*].names
that would hold a similar value. When I use the above line, I get the following error:
Expected an operand but found *
Is it possible to achieve that, or something similar? If so, how?
Thanks!
Yes, there is syntax for that:
* def variable = $response.entries.products[*].names
Read the docs: https://github.com/intuit/karate#get

Karate API framework - Validate randomly displayed items in response

I am using Karate API framework for the API automation and came across with one scenario, the scenario is when I am hitting a post call it gives me some json response and few of the items are having tags whereas few of them are showing tags as blank to get all the tags below is the feature file scenario line
* def getTags = get response.items[*].resource.tags
It is giving me response as
[
[
],
[
],
[
{
"tags" : "Entertainment"
}
],
[
],
[
{
"tags" : "Family"
}
],
As you can see out of 5 or 6 tags only 2 tags are having the value, so I want to capture if any tags value is showing or not. What would be the logic for the assertion considering these tags can all come as empty and sometimes with come with a string value. In above case "Family" & "Entertainment"
Thanks in advance !
* match each response.items[*].resource.tags == "##string"
This will validate that tags either doesn't exist or is a string.
I think you can use a second variable to strip out the empties, or maybe your original JsonPath should use .., you can experiment:
* def allowed = ['Music', 'Entertainment', 'Documentaries', 'Family']
* def response =
"""
[
[
],
[
],
[
{
"tags":"Entertainment"
}
],
[
],
[
{
"tags":"Family"
}
]
]
"""
* def temp = get response..tags
* print temp
* match each temp == "#? allowed.contains(_)"

Ramda remove objects from array based on nested value

I'm trying to remove an object from an array of objects if a certain value exists in nested data.
The data being returned from the API is shaped like this:
Array [
Object {
"id": "/db/Shifts/123",
"applicants": Object {
"applicants": Array [
"/db/User/12",
"/db/User/13",
],
},
Object {
"id": "/db/Shifts/456",
"applicants": Object {
"applicants": Array [
"/db/User/12",
"/db/User/14",
],
},
Object {
"id": "/db/Shifts/789",
"applicants": Object {
"applicants": Array [
"/db/User/13",
"/db/User/14",
],
},
]
Using Ramda, how would I filter out the shifts where User 12 exists in the array of applicants, which would be located at applicants.applicants.
I am not able to flatten the data in this case, the list of applicants for each shift does have to be an array contained in an object.
I tried this:
var hasApplied = pathEq(['applicants', 'applicants'], 'db/User/12');
console.log(filter(hasApplied, shifts));
But I don't think that is quite right because applicants.applicants is an array, I feed like I need to be feeding it one more function to get into the array of applicants but I'm not sure what.
Your use of R.pathEq is resulting in the user ID being compared with each array of IDs for equality, rather than checking whether each array contains the given ID.
You could instead make use of R.pathSatisfies along with R.contains
const hasApplied = R.pathSatisfies(R.contains('/db/User/12'), ['applicants', 'applicants'])

Text and caret in VID or R3-Gui

A simple example:
If I type #"w" in style "area" how do I get an #"z"? (ex. "qwerty ww" -> "qzerty zz")
As you want the conversion on the fly, you can either modify R3-GUI before loading. So load r3-gui.r3 down to your local directory. Then you add the line if key == #"w" [key: #"z"] to the function do-text-key, so it looks like
do-text-key: funct [
"Process text face keyboard events."
face [object!]
event [event! object!]
key
] [
text-key-map/face: face
text-key-map/shift?: find event/flags 'shift
if no-edit: not tag-face? face 'edit [
key: any [select/skip text-key-map/no-edit key 2 key]
]
either char? key [
if key == #"w" [key: #"z"]
text-key-map/key: key
switch/default key bind text-key-map/chars 'event [
unless no-edit [
insert-text-face face key
]
]
] [
if find event/flags 'control [
key: any [select text-key-map/control key key]
]
text-key-map/key: key
switch/default key text-key-map/words [return event]
]
none
]
Probably the official way would be to use on-key wih Rebol3
load-gui
view [
a: area on-key [ ; arg: event
if arg/type = 'key [
if arg/key == #"w" [arg/key: #"z"]
]
do-actor/style face 'on-key arg face/style
]
]
And finally a way to do this with Rebol2 on the fly
key-event: func [face event] [
if event/type = 'key [
if all [event/key = #"w" ] [
append a/text #"z"
focus a
view w
return false
]
]
event
]
insert-event-func :key-event
view w: layout [
a: area
]
After reading some files of r3-gui (text-caret.r3, text-cursor.r3, text-edit.r3, text-keys.r3, text.r3) and the editor, I found a solution that allows me to insert not only a character but also string:
do %r3-gui.r3
insertText-moveCursor-updateFace: func [
face
string
n-move
][
insert-text-face face string
move-cursor face 'left n-move false
update-text-caret face
see-caret face
show-later face
]
i-m-u: :insertText-moveCursor-updateFace
view [
area on-key [
either arg/type = 'key [
switch/default arg/key [
#"w" [i-m-u face/names/text-box "z" 0]
#"[" [i-m-u face/names/text-box "[]" 1]
#"$" [i-m-u face/names/text-box "func [] []" 4]
] [
;switch/default
do-actor/style face 'on-key arg face/style
]
] [
;arg/type != 'key
do-actor/style face 'on-key arg face/style
]
]
]
Area is a compound styles. It is composed of a text-box and a scroller. They are contained in face/names.

Rebol switch and type?

Why do I have to cast typeof to string with switch to make it work ?
This doesn't work:
typeof: type? get 'optional
switch typeof [
word! [
print "word"
]
string! [
print "string"
]
]
This works:
typeof: type? get 'optional
switch to-string typeof [
"word" [
print "word"
]
"string" [
print "string"
]
]
switch type?/word :optional [
word! [ print "word" ]
string! [ print "string" ]
]
OR
switch type? :optional reduce [
word! [ print "word" ]
string! [ print "string" ]
]
The reason is that the REBOL doesn't reduce ("evaluate") the cases in the switch statement. Without the /word refinement, the type? function returns a datatype!, but the switch statement tries to match this against a word!, and it fails.
I realize this might be confusing, so your best bet is either to convert the type to a string (as you did), or use one of the two idioms I've suggested. I prefer the first one, using type?/word.