Condition check on Mono object - reactive

I am doing Zipwith and Zipwhen operations on Mono object but I got a requirement to check the field value in mono and then proceed with Zip with and when. How can I implement this?

Related

Passing An Object Instance By Value In Dart

I have an object that was created with GetxController and it has a list field. I want to select a specific item in that list and change some parameters. But I should be able to cancel this changing scenario. Because when I select an item and change it, also change that class list item.
In Dart, objects pass by reference. But I need to pass it by value for canceling change. There's any way to pass an object instance by value?
In this kind of scenario, you should try to use immutable types.
There are good Dart libraries for that, even if the language doesn't have native support for it... with truly immutable data types, you essentially get pass-by-value semantics. They also make it easy to make copies of your data with small modifications on the returned value (while the original obviously remains unmodified).
Example packages you could use:
built_collection
built_value
freezed
No.
But you can just make a copy yourself and pass that. And depending on whether the change was confirmed you can eiter copy it back into your list or not.

Iterating through objects in project tree

As the title says: I wonder, whether it's possible to iterate through the object tree of an AnyLogic project.
Probably it would help, if I provide more information what I want to do. Take the following project tree:
I want to check for every delay object in my model, whether or not it currently contains agents. One possibility would be to add all delay objects manually to a collection object and to iterate through the elements of the collection. However, this approach would result in a lot of manual work, as I require to perform similar requests for other object types. In my opinion, the most convenient solution is to iterate through the project tree and to identify with 'isinstanceof' the objects I want to analyze.
Does anyone know a solution or another approach, which requires similar less effort?
Best regards,
Sebastian
You can loop through all objects in Main doing this:
for (Object currObject : ((Agent)getRootAgent()).getEmbeddedObjects()) {
if (currObject instanceof Delay) {
// you found a Delay object
}
}

Deserializing a Unity prefab/scene as nested hashtable of key/value pairs

I'm trying to write a tool that scans through our Unity (2017.4.22) prefabs and scene files to look for Monobehaviour properties that don't exist in a release build. I've created a c# console project (incorporating YamlDotNet 6.1.2), and from this project I refer to Unity's 'Assembly-CSharp-firstpass.dll' and 'Assembly-CSharp.dll' dlls.
I was wondering if anyone has been able to configure YamlDotNet to parse any given prefab/scene file into a generic key/value data structure (with an arbitrary number of nested levels) in memory, so I can iterate it and use reflection to determine if fields exist.
If you're wondering why I need to do this manually, it's because I'm scanning for fields that don't exist in release builds. The only way to do that is to recompile 'Assembly-CSharp-firstpass' and 'Assembly-CSharp' with UNITY_EDITOR removed (and all code from files within a 'Editor' subfolder) culled. I can't do this in-editor (obviously) so that's why this has to be a standalone tool.
Everything I've tried has resulted in crashes. Here's what I tried:
I downloaded the YamlDotNet 6.1.2 source
Tried to deserialize a prefab using Deserialize(...). Received this error: "Encountered an unresolved tag 'tag:unity3d.com,2011:1'"
I then found this custom Type resolver, which I integrated: https://gist.github.com/derFunk/795d7a366627d59e0dbd
I then started receiving this exception: "Exception during deserialization ---> System.InvalidOperationException: Failed to create an instance of type 'UnityEngine.GameObject'"
I'm guessing this is is happening because I'm trying to instantiate a GameObject in an environment that doesn't fully support GameObjects (I am in a standalone C# project after all).
But I don't actually need to instantiate any GameObjects. I just want to parse the values. Does this make sense to anyone? I found a few other questions here but they don't seem to handle YAML files that are at the same complexity as Unity's prefabs.
Thanks in advance,
Jeff
Your guess is correct. Because you are resolving the tag:unity3d.com,2011:* tags to UnityEngine.GameObject and related types, then the deserializer attempts to create an instance of the corresponding type when it encounters the tags.
You could opt to always resolve the tag to Dictionary<string, object> (or Dictionary<object, object> if the keys are not always strings). Then always get dictionaries.
In your case it is probably simpler to load the YAML stream using YamlDotNet.RepresentationModel.YamlStream. This will give you a representation of the YAML document that will be more suitable for your use case.
Here's the official example on how to do it: https://github.com/aaubry/YamlDotNet/wiki/Samples.LoadingAYamlStream
// Load the stream
var yaml = new YamlStream();
yaml.Load(input);
// Examine the stream
var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

Swift SpriteKit GameplayKit check GKStateMachine does not equal state

I have just finished converting my game using the Entity and Component base architecture (GameplayKit) that apple introduced in iOS9.
I cannot figure out how to check that a current state (GKStateMachine) does not equal a state.
Say I want to check that the currentState is equal to my GameOverState, I would say this
if self.stateMachine.currentState is GameOverState {...
How would I check if the current state does not equal GameOverState, the "... is ..." sytanx is new to me so I am not sure how to call it.
I ran into this issue myself. It doesn't seem like ther is an inverse to is, so the only option I could see was to wrap the conditional statement to invert the boolean. So you would do like the following...
if !(self.stateMachine.currentState is GameOverState) {...
I found it hard to find documentation... so for yours, and others reference:
Documentation on the is operator (section titled "Type-Casting Operators")

how will spring mongodbtemplate check if object already exists

I am using save method in mongdbtemplate of spring mongo(api link provided below).
http://static.springsource.org/spring-data/mongodb/docs/1.2.x/api/org/springframework/data/mongodb/core/MongoTemplate.html#save(java.lang.Object, java.lang.String)
I am trying to understand how will mongdbtemplate check if object is already existing.
I am assuming the it uses equals method on object passed, please let me know if it is otherwise
There is no magic code that mongodbtemplate uses internally. MongoDB natively supports the concept of upsert.