Iterating and mapping List of list - grails

I have a list of list like this
[[emplid:01,emplname:alan],[emplid:02,emplname:john],[emplid:03,emplname:ali]]
i need the output as
[emplid:01,emplid:02,emplid03]
can anyone suggest the looping in java or gorrvy

1st off, your collection is a list of maps, not lists. Second, your output is impossible, if you want to get a map, as the later doesn't support doublets as keys

It's impossible to get the output you requested, but you can get a list of emplid's:
[
[emplid:01,emplname:'alan'],
[emplid:02,emplname:'john'],
[emplid:03,emplname:'ali']
].collect {
it.emplid
}
The output of the above is: [1, 2, 3]
For an output like [emplid1, emplid2, emplid3] you can do this:
[
[emplid:01,emplname:'alan'],
[emplid:02,emplname:'john'],
[emplid:03,emplname:'ali']
].collect {
"emplid${it.emplid}"
}

Related

How do I indent a bulleted list with the Google Docs API

Starting with a Google Doc that looks like:
* Item
I'm hoping to make a series of API calls to turn the doc into:
* Item
- Subitem
But, I can't figure out how to do this with the API. A CreateParagraphBulletRequest doesn't have an indent level I can specify. The documentation suggests:
The nesting level of each paragraph will be determined by counting leading tabs in front of each paragraph. To avoid excess space between the bullet and the corresponding paragraph, these leading tabs are removed by this request. This may change the indices of parts of the text.
However, prepending tabs to the beginning of an InsertTextRequest will prepend the tab character, rather than changing the indent:
* Item
* Subitem
Does anyone have any ideas for what I may be doing wrong?
I believe your goal as follows.
You want to create a nested list using Google Docs API.
At first, a list, which has one item as 1st level, is existing in the Google Document. It's as follows.
- item1
Under this situation, you want to insert a nested item to the existing list as 2nd level. It's as follows.
- item1
- item2
Points for achieving your goal:
In this case, in order to insert the item to the existing list as the 2nd level, in my experience, I couldn't directly insert it. In my case, as a workaround, I'm using the following flow.
Insert a text \n\titem2\n for 2nd level using insertText request.
In this case, the 1st level is also inserted. It seems that in order to insert the deep level items, it is required to set from the 1st level and convert to the list with the bullets.
Using createParagraphBullets, it gives the bullets to the list. By this, \t is converted to the nested items.
Remove the bullet of the 1st level.
Remove the line break.
Sample request body:
When above flow is reflected to the request body of the method of batchUpdate in Docs API, it becomes as follows.
{
"requests": [
{
"insertText": {
"text": "\n\titem2\n",
"location": {
"index": 7
}
}
},
{
"createParagraphBullets": {
"range": {
"startIndex": 1,
"endIndex": 15
},
"bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
}
},
{
"deleteParagraphBullets": {
"range": {
"startIndex": 7,
"endIndex": 8
}
}
},
{
"deleteContentRange": {
"range": {
"startIndex": 7,
"endIndex": 8
}
}
}
]
}
Result:
When above request body is used, the following result is obtained.
Before:
After:
Note:
Although I had looked for other methods for using Docs API without changing the existing list, unfortunately, I cannot still find them. I thought that in order to insert the deep nested items to the existing list, in the current stage, the items might be required to be given from 1st level using \t. Unfortunately, I'm not sure whether this is the specification. So, for example, how about requesting this for the issue tracker as the future request? Ref
References:
Working with lists
documents.batchUpdate

How to correctly return a list of dictionaries in Zapier Code (Python)?

The Zapier code documentation says that the output of a code zap can be either a dictionary or a list of dictionaries (See "Data Variable" section: https://zapier.com/help/code-python/).
When doing this,
output = [{'Booking':'Shirt'},{'Booking':'Jeans'}]
the output of the code returns only the first dictionary, however:
runtime_meta__duration_ms: 2
runtime_meta__memory_used_mb: 22
id: [redacted]
Booking: Shirt
Fields with no value:
runtime_meta__logs
What am I doing wrong here? Thanks a lot!
David from the Zapier platform team here. Code steps returning an array is a mostly undocumented (because there's no UI support and it's confusing, as you can tell) feature.
When testing, it'll only show the first item in the array. When it runs for real, all steps after the code step will run for each item in the array. The task history will reflect this
So set up the zap and turn on and it'll work like you expect.
Sorry for the confusion and let me know if you have any other questions!
For anyone still looking for an answer to this questions, below is what find out returning list in Zapier.
# first import and convert your input value to an array.
# special note any line items imported into a python variable are converted to list format.
my_items = input_data['my_CSV_string']
my_list_of_items = my_items.split(",")
# Create a new list array
my_new_list = []
length = len(my_list_of_items)
#Do all your computations
for i in range(length):
my_new_list.append(float(my_list_of_items[i])*1.5)
# After completing any tasks you can return the list as follows,
# If you are using line items keep the list in its original format
return {
'my_processed_values': my_new_list,
'original_values': my_list_of_items
}
# If you want to return it as a CSV "basically making the array flat"
my_old_CSV_list= ','.join(map(str, my_list_of_items))
my_new_CSV_list= ','.join(map(str, my_new_list))
return {
'my_processed_cvs_values': my_new_CSV_list,
'original_values': my_list_of_items
}
Hope this helps. I am not a Python expert but in theory the more lists used the longer the zap will take to process. Try to keep your python processing time to the lowest.
Best,

Ruby on Rails statement executed on an array check if subelement string is unique

I have an array objects, for this example lets call it Diff. These diffs have multiple fields that are not all the same (old_image, new_image, url, etc). new_image and old_image in this case have fields on them, most importantly a field called image_file_name.
I want to get an array of all the diffs with an unique old_image.image_file_name i.e. no diff should have an old_image with the same file name.
I believe the logic should look something like this.
unique_diffs = Array.new
#diff.build.diffs.each { |diff|
if diff.old_image.image_file_name != #diff.old_image.image_file_name
unique_diffs.push(diff)
end
}
Or something like this
#unique_diffs = #diff.build.diffs.map{|diff| diff.old_image.image_file_name}.uniq
Any help would be much appreciated.
Try something like this:
Diff = Struct.new(:old_image)
Image = Struct.new(:image_file_name)
diffs = [
Diff.new(Image.new('name1')),
Diff.new(Image.new('name2')),
Diff.new(nil),
Diff.new(Image.new('name1')),
]
uniqs = diffs.select { |diff| diff.old_image }.uniq { |diff| diff.old_image.image_file_name }
p uniqs # prints Diff with name1 and Diff with name 2
The only important line is the one that calls select and uniq.
You need to use select to leave only the diffs with the old image, and then use uniq to drop those with the duplicated image file names.
I ended up using the loop, I was hoping to make this cleaner with the uniq function but it didn't seem to work, it gave me back all the diffs instead of the ones with the unique old image filename.
#diff.build.diffs.each { |diff|
if diff.old_image.image_file_name == #diff.old_image.image_file_name
# Logic went here
end
}
Still open to improving this but for now this will have to do.

Zend2: Outputting a single form element if its a radio button list?

I have a radio button list with three options: daily, monthly, weekly. I want a way to access each one individually. For example:
echo $this->formElement($form->get('iteration'));
Will print out all three values, with their labels:
[ ] daily
[ ] monthly
[ ] weekly
I want a way to iterate over all the elements. Something like this:
foreach ($this->formElements($form->get('iteration') as $element) {
echo $this->formElement($element);
}
But that doens't work. Any thoughts?
When you're using the Zend\Form\Element\Radio form element with multiple options, you can iterate over the options like this:
foreach ($form->get('iteration')->getValueOptions() as $option) {
...
}
But if you want to output the options separately, you'd need to create multiple Zend\Form\Element\Radio's.

Dust.js - iterate through an iterated anonymous array

I have this data structure in dust:
{ 'items' : [
[ 'apples', "$1.00" , "Delicious" ],
[ 'oranges', "$2.00" , "Juicy" ],
]
}
I'm trying to access the inner items, and can't figure out how.
I can address the entire array of the current loop via {.} , but i can't seem to access the items within it. ( I could do this in Mustache )
I was expecting something like this to work...
{#items}
<b>{.[0]}</b> <em>only {.[1]}!</em>
<p>{.[2]}</p>
{/items}
When I ran your example in the dust playground: http://linkedin.github.io/dustjs/test/test.html
the output I got was:
<b>apples</b> <em>only $1.00!</em><p>Delicious</p><b>oranges</b> <em>only $2.00!</em><p>Juicy</p>
This looks to be what you were expecting. I believe fixes in this area after your post likely made this work. Grab the latest version of dust.

Resources