Tutorial by Examples

Any fold can be run in the opposite direction with the help of the Dual monoid, which flips an existing monoid so that aggregation goes backwards. newtype Dual a = Dual { getDual :: a } instance Monoid m => Monoid (Dual m) where mempty = Dual mempty (Dual x) `mappend` (Dual y) = Dua...
To instantiate Foldable you need to provide a definition for at least foldMap or foldr. data Tree a = Leaf | Node (Tree a) a (Tree a) instance Foldable Tree where foldMap f Leaf = mempty foldMap f (Node l x r) = foldMap f l `mappend` f x `mappend` foldMap f r fo...
The function strtok breaks a string into a smaller strings, or tokens, using a set of delimiters. #include <stdio.h> #include <string.h> int main(void) { int toknum = 0; char src[] = "Hello,, world!"; const char delimiters[] = ", !"; char *to...
import Data.Traversable as Traversable data MyType a = -- ... instance Traversable MyType where traverse = -- ... Every Traversable structure can be made a Foldable Functor using the fmapDefault and foldMapDefault functions found in Data.Traversable. instance Functor MyType where ...
Implementations of traverse usually look like an implementation of fmap lifted into an Applicative context. data Tree a = Leaf | Node (Tree a) a (Tree a) instance Traversable Tree where traverse f Leaf = pure Leaf traverse f (Node l x r) = Node <$> traverse f l <*...
A traversal can be run in the opposite direction with the help of the Backwards applicative functor, which flips an existing applicative so that composed effects take place in reversed order. newtype Backwards f a = Backwards { forwards :: f a } instance Applicative f => Applicative (Backward...
The standard (section 23.3.7) specifies that a specialization of vector<bool> is provided, which optimizes space by packing the bool values, so that each takes up only one bit. Since bits aren't addressable in C++, this means that several requirements on vector are not placed on vector<bool...
When the following is compiled, it will return a different value depending on which directives are defined. // Compile with /d:A or /d:B to see the difference string SomeFunction() { #if A return "A"; #elif B return "B"; #else return "C"; #endif ...
Compiler warnings can be generated using the #warning directive, and errors can likewise be generated using the #error directive. #if SOME_SYMBOL #error This is a compiler Error. #elif SOME_OTHER_SYMBOL #warning This is a compiler Warning. #endif
A compiler symbol is a keyword that is defined at compile-time that can be checked for to conditionally execute specific sections of code. There are three ways to define a compiler symbol. They can be defined via code: #define MYSYMBOL They can be defined in Visual Studio, under Project Propert...
Use #region and #endregion to define a collapsible code region. #region Event Handlers public void Button_Click(object s, EventArgs e) { // ... } public void DropDown_SelectedIndexChanged(object s, EventArgs e) { // ... } #endregion These directives are only beneficial whe...
Line #line controls the line number and filename reported by the compiler when outputting warnings and errors. void Test() { #line 42 "Answer" #line filename "SomeFile.cs" int life; // compiler warning CS0168 in "SomeFile.cs" at Line 42 #line defa...
Sometimes you may have a form and want to submit it using ajax. Suppose you have this simple form - <form id="ajax_form" action="form_action.php"> <label for="name">Name :</label> <input name="name" id="name" type="t...
package main import ( "log" "net/http" ) func main() { // Create a mux for routing incoming requests m := http.NewServeMux() // All URLs will be handled by this function m.HandleFunc("/", func(w http.ResponseWriter, r *http.Reque...
#import <Foundation/Foundation.h> @interface Car:NSObject { NSString *CarMotorCode; NSString *CarChassisCode; } - (instancetype)initWithMotorValue:(NSString *) motorCode andChassisValue:(NSInteger)chassisCode; - (void) startCar; - (void) stopCar; @end @implementation Car...
C11 Reading an object will cause undefined behavior, if the object is1: uninitialized defined with automatic storage duration it's address is never taken The variable a in the below example satisfies all those conditions: void Function( void ) { int a; int b = a; } 1 (Quo...

PHP

The following will retrieve a channel object for the twitch channel and echo the response. $channelsApi = 'https://api.twitch.tv/kraken/channels/'; $channelName = 'twitch'; $clientId = '...'; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_HTTPHEADER=> array(...
The following will log the JSON response from the API to the console if the request was successful, otherwise it will log the error. var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://api.twitch.tv/kraken', true); xhr.setRequestHeader('Client-ID', '...'); xhr.onload = function(...
The following will retrieve a channel object for the twitch channel. If the request was successful the channel object will be logged to the console. $.ajax({ type: 'GET', url: 'https://api.twitch.tv/kraken/channels/twitch', headers: { 'Client-ID': '...' }, success: function(data...
Array types inherit their equals() (and hashCode()) implementations from java.lang.Object, so equals() will only return true when comparing against the exact same array object. To compare arrays for equality based on their values, use java.util.Arrays.equals, which is overloaded for all array types...

Page 97 of 1336