Flatten array in PowerShell

Piping is the correct way to flatten nested structures, so I’m not sure what would be more “elegant”. Yes, the syntax is a bit line-noisy looking, but frankly quite serviceable. 2020 Edit The recommended syntax these days is to expand % to ForEach-Object. A bit more verbose but definitely more readable: @($a | ForEach-Object {$_}).count

Publishing/subscribing multiple subsets of the same server collection

Could you not just use the same query client-side when you want to look at the items? In a lib directory: enabledItems = function() { return Items.find({enabled: true}); } processedItems = function() { return Items.find({processed: true}); } On the server: Meteor.publish(‘enabled_items’, function() { return enabledItems(); }); Meteor.publish(‘processed_items’, function() { return processedItems(); }); On the client … Read more

What is the difference between find and firstOrNull?

In this thread from 2014, Kotlin community members and JetBrains staff discuss the merits of the different methods find and firstOrNull: https://youtrack.jetbrains.com/issue/KT-5185 While not an official statement, JetBrains’ employee Ilya Ryzhenkov describes it as: I think we can undeprecate find and make it an alias to firstOrNull. Much like indexOf has well-known semantics, find is … Read more

.collect with an index

Since Groovy 2.4.0 there is a withIndex() method which gets added to java.lang.Iterable. So, in a functional fashion (no side effect, immutable), it looks like def myList = [ [position: 0, name: ‘Bob’], [position: 0, name: ‘John’], [position: 0, name: ‘Alex’], ] def result = myList.withIndex().collect { element, index -> [position: index, name: element[“name”]] }

What is the use case for flatMap vs map in kotlin

Consider the following example: You have a simple data structure Data with a single property of type List. class Data(val items : List<String>) val dataObjects = listOf( Data(listOf(“a”, “b”, “c”)), Data(listOf(“1”, “2”, “3”)) ) flatMap vs. map With flatMap, you can “flatten” multiple Data::items into one collection as shown with the items variable. val items: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)