nested

Statically “extend” a record-ish data type without indirection hassle

烈酒焚心 提交于 2019-12-10 01:00:55
问题 I am currently working with a three-level process for which I need some information to flow being accessed and updated. The information is also three-leveled, in such a way that a process at one level may need to access/update information at its level and at higher levels. type info_0 = { ... fields ... } type info_1 = { ... fields ... } type info_2 = { ... fields ... } fun0 will do some stuff with an info_0 , then pass it to fun1 along with an info_1 , then get back the resulting info_0 and

Nested datatype for square matrices

跟風遠走 提交于 2019-12-09 16:53:23
问题 I am trying to understand how this datatype (Square) represents square matrices. type Square = Square' Nil data Square' t a = Zero (t (t a) ) | Succ (Square' (Cons t) a) data Nil a = Nil data Cons t a = Cons a (t a) So. What is t here? I suppose it is one of the types declared above. I decided to start with the simplest, so Zero (Nil (Nil Int)) If I put integer 4 as a value, is this a matrix (4) ? Suppose it is something. Now, what is this: Succ ( Zero (Cons t) a) if I am right about t , then

How to access an outer member from a nested object literal?

☆樱花仙子☆ 提交于 2019-12-09 16:51:51
问题 In the following code, can the x member be accessed from the nested object literal? var outer = { x : 0, inner: { a : x + 1, // 'x' is undefined. b : outer.x + 1, // 'outer' is undefined. c : this.x + 1 // This doesn't produce an error, } // but outer.inner.c is NaN. } 回答1: In the way you put it - no. You need two stages construction, this will work: var outer = { x : 0 }; // outer is constructed at this point. outer.inner = { b : outer.x + 1 // 'outer' is defined here. }; 回答2: Not in the

How do I force nested list items to be the same width as parent list item?

ⅰ亾dé卋堺 提交于 2019-12-09 16:13:53
问题 I have a horizontal parent list. Some of the list items display a nested vertical list when clicked. How do I force the items in the vertical sub list to be the same width as the parent list item? See jsFiddle. HTML: <ul class="mainMenu horizontalMenu bulletless fullWidth bold"> <li class="showSubMenu"> <div>Resumes & Cover Letters ▾ </div> <ul class="mainSubMenu bulletless"> <li><a>Resumes</a></li> <li><a>Cover Letters</a></li> <li><a>Interviews</a></li> </ul> </li><li><a>Other Link</a> </li

Elasticsearch - Filter where (one of nested array) and (all of nested array)

倖福魔咒の 提交于 2019-12-09 14:32:45
问题 TL;DR - How do I check whether one-of and all-of a nested array meet specified criteria? I have a document . Each document has an array of nested outer objects, who themselves have a list of nested inner objects. I need to perform a filter for all documents where at least one of the document's outer nested objects match. When I say match, I mean that all the outer nested objects' inner objects match in some way. Here's an example mapping for reference; { "document" : { "properties" : { "name"

Nested models of the same 'class' in the Backbone.js framework?

帅比萌擦擦* 提交于 2019-12-09 13:58:00
问题 I'm new to Backbone. Is it possible to define a Model in backbone which contains a list of Models of the same type? Example: MyModel = Backbone.Model.extend({ initialize: function() { nestedMyModels:new Array(); }, addMyModel: function(aModel) { // Code here would push() aModel onto array }, render: function() { // Loop through array calling render() recursively } }); I would then have a View which started a recursive call to render(). Example: MyView = Backbone.View.extend({ render:function(

Nested Objects Best Practice

醉酒当歌 提交于 2019-12-09 12:14:18
问题 What is the best practice for referencing nested objects? Say I have the following: class Outer { private InnerA innerA; //getters and setters } class InnerA { private InnerB innerB; //getters and setters } class InnerB { private String someString; //getters and setters } and in my controller or service class I need to check the someString String variable of the InnerB class to make sure it is not null or not empty so I do this: if (getOuter().getInnerA().getInnerB().getSomeString() != null &

Rails nested with_option :if used in validation

白昼怎懂夜的黑 提交于 2019-12-09 08:49:04
问题 validate :updatable? # First validation there is with_options :if => Proc.new { |object| object.errors.empty? } do |updatable| updatable.with_options :if => "self.current_step == basic" do |step| validates .... bla-bla bla So, before any validations are made, the updatable subroutine is called and it populates the errors[:base] array with appropriate errors, meaning that object is not updatable. And I wanted it to skip the rest of the validations if any errors are found in this subroutine,

Find Maximum Value in Nested Dictionary and return Key

蓝咒 提交于 2019-12-09 06:42:24
So I have this block of code dictionary = { 'key1': {'a': 1, 'b': 2, 'c': 10}, 'key2': {'d': 1, 'e': 1, 'c': 11}, 'key3': {'d': 2, 'b': 1, 'g': 12}} and list1 = (a,b,c) What I want to do is run a loop that finds the maximums of all the items in the list and returns the key. So for example, the maximum of 'c' would return 'key2', the maximum of 'b' would return 'key1', etc. So far I have for value in list1: m = max(dictionary, key=lambda v: dictionary[v][value]) print(m + "\n") But this only works if the same subkey exists in all keys in the dictionary. Any ideas on what to do? Use float('-inf'

Python - Dynamic Nested List

Deadly 提交于 2019-12-09 06:14:01
问题 So I'm trying to generate a nested list in Python based on a width and a height. This is what I have so far: width = 4 height = 5 row = [None]*width map = [row]*height Now, this obviously isn't quite right. When printed it looks fine: [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]] But attempting to assign a value to a position like so: map[2][3] = 'foo' I get: [[None, None, None, 'foo'], [None, None, None,