traversal

An example of a Foldable which is not a Functor (or not Traversable)?

徘徊边缘 提交于 2019-11-27 18:27:34
A Foldable instance is likely to be some sort of container, and so is likely to be a Functor as well. Indeed, this says A Foldable type is also a container (although the class does not technically require Functor , interesting Foldable s are all Functor s). So is there an example of a Foldable which is not naturally a Functor or a Traversable ? (which perhaps the Haskell wiki page missed :-) ) Sjoerd Visscher Here's a fully parametric example: data Weird a = Weird a (a -> a) instance Foldable Weird where foldMap f (Weird a b) = f $ b a Weird is not a Functor because a occurs in a negative

javascript selectors

我的未来我决定 提交于 2019-11-27 18:09:39
问题 How does one select DOM elements in javascript? Like for example: <div class="des"> <h1>Test</h1> <div class="desleft"> <p>Lorem Ipsum.</p> </div> <div class="Right"> <button>Test</button> </div> </div> Now how do i select h1 ? This is just a part of a bigger Page, so cannot use getElementsByTagName() , since others might get selected. Also since there might be other h1 's in the document later, i cannot attach the index(body's) to above. Is there a simple way to select, say <h1> tag which is

Traverse a XML using Recursive function

只谈情不闲聊 提交于 2019-11-27 13:48:56
How can I traverse (read all the nodes in order) a XML document using recursive functions in c#? What I want is to read all the nodes in xml (which has attributes) and print them in the same structure as xml (but without Node Localname) Thanks using System.Xml; namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { var doc = new XmlDocument(); // Load xml document. TraverseNodes( doc.ChildNodes ); } private static void TraverseNodes( XmlNodeList nodes ) { foreach( XmlNode node in nodes ) { // Do something with the node. TraverseNodes( node.ChildNodes ); } } } }

How to traverse clang AST manually ?

别来无恙 提交于 2019-11-27 11:34:37
问题 I can traverse the specific subtrees of clang AST using the recursivevisitor class but what I want to do is to traverse the clang AST node by node. I'd be really grateful if anybody can help me with this. Thanks in advance. 回答1: RecursiveASTVisitor can do what you need. Implementing the member methods TraverseDecl(Decl *x) , TraverseStmt(Stmt *x) and TraverseType(QualType x) for your RecursiveASTVisitor`-derived class (e.g. MyClass) will do the trick. Combined, those three methods will take

Jquery how to find an Object by attribute in an Array

匆匆过客 提交于 2019-11-27 11:25:15
Given I have an array of "purpose" objects: //array of purpose objects: var purposeObjects = [ {purpose: "daily"}, {purpose: "weekly"}, {purpose: "monthly"} ]; (for simplicity i am omitting other attributes) Now I want to have a method that returns a specific one of the objects if a matching purpose name is found. This is not working: function findPurpose(purposeName){ return $.grep(purposeObjects, function(){ return this.purpose == purposeName; }); }; findPurpose("daily"); but it actually returns an empty array: [] I am using JQuery 1.5.2. I have also tried with $.each() but with no luck.

jQuery find parent form

房东的猫 提交于 2019-11-27 09:11:30
问题 i have this html <ul> <li><form action="#" name="formName"></li> <li><input type="text" name="someName" /></li> <li><input type="text" name="someOtherName" /></li> <li><input type="submit" name="submitButton" value="send"></li> <li></form></li> </ul> How can i select the form that the input[name="submitButton"] is part of ? (when i click on the submit button i want to select the form and append some fields in it) 回答1: I would suggest using closest, which selects the closest matching parent

PHP - Find parent key of array

安稳与你 提交于 2019-11-27 05:28:22
I'm trying to find a way to return the value of an array's parent key. For example, from the array below I'd like to find out the parent's key where $array['id'] == "0002". The parent key is obvious because it's defined here (it would be 'products'), but normally it'd be dynamic, hence the problem. The 'id' and value of 'id' is known though. [0] => Array ( [data] => [id] => 0000 [name] => Swirl [categories] => Array ( [0] => Array ( [id] => 0001 [name] => Whirl [products] => Array ( [0] => Array ( [id] => 0002 [filename] => 1.jpg ) [1] => Array ( [id] => 0003 [filename] => 2.jpg ) ) ) ) ) A

Iterating over element attributes with jQuery

杀马特。学长 韩版系。学妹 提交于 2019-11-27 04:20:44
I know individual attributes can be retrieved with the attr() method, but I'm trying to iterate over all of the attributes for an element. For context, I'm using jQuery on some XML... <items> <item id="id123" name="Fizz" value="Buzz" type="xyz"> <subitem name="foo"> <subitem name="bar"> </item> <item id="id456" name="Bizz" value="Bazz" type="abc"> <subitem name="meh"> <subitem name="hem"> </item> </items> I am already able to iterate over the items with... $(xml).find('item').each(function() { // Do something to each item here... }); But I'd like to be able to get an array of attributes for

How to get nodes lying inside a range with javascript?

我与影子孤独终老i 提交于 2019-11-27 04:00:40
I'm trying to get all the DOM nodes that are within a range object, what's the best way to do this? var selection = window.getSelection(); //what the user has selected var range = selection.getRangeAt(0); //the first range of the selection var startNode = range.startContainer; var endNode = range.endContainer; var allNodes = /*insert magic*/; I've been been thinking of a way for the last few hours and came up with this: var getNextNode = function(node, skipChildren){ //if there are child nodes and we didn't come from a child node if (node.firstChild && !skipChildren) { return node.firstChild;

Traversing unordered lists using Javascript/Jquery

帅比萌擦擦* 提交于 2019-11-27 03:49:56
问题 Lets say I have an unordered nested list: <ul> <li>Item a1</li> <li>Item a2</li> <li>Item a3</li> <ul> <li>Item b1</li> <li>Item b2</li> <li>Item b3</li> <ul> <li>Item c1</li> <li>Item c2</li> <li>Item c3</li> </ul> <li>Item b4</li> </ul> <li>Item a4</li> </ul> I need to traverse it and save it in a two dimensional array (ultimately I'm just trying to convert it into a JSON entity) I am allowed to use both Jquery AND/OR Javascript. How should I proceed? Thanks 回答1: I'm not sure exactly what