Tutorial by Examples

A Traversal' s a shows that s has 0-to-many as inside of it. toListOf :: Traversal' s a -> (s -> [a]) Any type t which is Traversable automatically has that traverse :: Traversal (t a) a. We can use a Traversal to set or map over all of these a values > set traverse 1 [1..10] [1,1,1,...
If you have a f :: Lens' a b and a g :: Lens' b c then f . g is a Lens' a c gotten by following f first and then g. Notably: Lenses compose as functions (really they just are functions) If you think of the view functionality of Lens, it seems like data flows "left to right"—this might ...
main.go: package main import ( "fmt" ) func main() { fmt.Println(Sum(4,5)) } func Sum(a, b int) int { return a + b } main_test.go: package main import ( "testing" ) // Test methods start with `Test` func TestSum(t *testing.T) { go...
If you want to measure benchmarks add a testing method like this: sum.go: package sum // Sum calculates the sum of two integers func Sum(a, b int) int { return a + b } sum_test.go: package sum import "testing" func BenchmarkSum(b *testing.B) { for i := 0; i < ...
This type of testing is popular technique for testing with predefined input and output values. Create a file called main.go with content: package main import ( "fmt" ) func main() { fmt.Println(Sum(4, 5)) } func Sum(a, b int) int { return a + b } After you r...
This type of tests make sure that your code compiles properly and will appear in the generated documentation for your project. In addition to that, the example tests can assert that your test produces proper output. sum.go: package sum // Sum calculates the sum of two integers func Sum(a, b in...
You can use Optional Chaining in order to call a method, access a property or subscript an optional. This is done by placing a ? between the given optional variable and the given member (method, property or subscript). struct Foo { func doSomething() { print("Hello World!") ...
SelectorDescription*Universal selector (all elements)divTag selector (all <div> elements).blueClass selector (all elements with class blue).blue.redAll elements with class blue and red (a type of Compound selector)#headlineID selector (the element with "id" attribute set to headline)...
Here is a simple model that we will use to run a few test queries: class MyModel(models.Model): name = models.CharField(max_length=10) model_num = models.IntegerField() flag = models.NullBooleanField(default=False) Get a single model object where the id/pk is 4: (If there are no...
Context processor to determine the template based on group membership(or any query/logic). This allows our public/regular users to get one template and our special group to get a different one. myapp/context_processors.py def template_selection(request): site_template = 'template_public.html...
Conditions may also be evaluated in a single line using the ternary operator: If you wanted to determine the minimum and maximum of two variables, you could use if statements, like so: let a = 5 let b = 10 let min: Int if a < b { min = a } else { min = b } let max: Int ...
Create a new playground file: First option: From Xcode welcome screen, select the first option (Get started with a playground). Second option: From menu select File → New → Playground (⌥⇧⌘N). Name your playground and select the platform (iOS/macOS/tvOS), then click Next. ...
Using Playground it is easy to see that happens inside loops or objects while the change is happening. For example, in the code below, the value of x will change from 1 to 4. import UIKit for x in [1, 2, 3, 4] { x } (1) Clicking on the eye symbol on the right will give us a quick look. (2...
models.py : from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import ( AbstractBaseUser, BaseUserManager, PermissionsMixin) from django.utils import timezone from django.utils.translation import ugettext_lazy as _ class UserManage...
The ls command's -S option sorts the files in descending order of file size. $ ls -l -S ./Fruits total 444 -rw-rw-rw- 1 root root 295303 Jul 28 19:19 apples.jpg -rw-rw-rw- 1 root root 102283 Jul 28 19:19 kiwis.jpg -rw-rw-rw- 1 root root 50197 Jul 28 19:19 bananas.jpg When used with the -r o...
Install gunicorn pip install gunicorn From django project folder (same folder where manage.py resides), run the following command to run current django project with gunicorn gunicorn [projectname].wsgi:application -b 127.0.0.1:[port number] You can use the --env option to set the pat...
Go supports pointers, allowing you to pass references to values and records within your program. package main import "fmt" // We'll show how pointers work in contrast to values with // 2 functions: `zeroval` and `zeroptr`. `zeroval` has an // `int` parameter, so arguments will be ...
public IEnumerable<int> F1() { for (int i = 0; i < 3; i++) yield return i; //return F2(); // Compile Error!! foreach (var element in F2()) yield return element; } public int[] F2() { return new[] { 3, 4, 5 }; }
What’s a component? A component is basically a directive that uses a simpler configuration and that is suitable for a component-based architecture, which is what Angular 2 is all about. Think of a component as a widget: A piece of HTML code that you can reuse in several different places in y...
OptionSetType is a protocol designed to represent bit mask types where individual bits represent members of the set. A set of logical and/or functions enforce the proper syntax: struct Features : OptionSet { let rawValue : Int static let none = Features(rawValue: 0) static let feature0 = F...

Page 153 of 1336