Tutorial by Examples: ga

Anamorphisms, or unfolds, model primitive corecursion. ana builds up a fixpoint layer by layer, using a coalgebra function (or unfolding function) to produce each new layer. ana requires a Functor instance for the template type f. ana :: Functor f => (a -> f a) -> a -> Fix f ana f = Fi...
It's common to structure a program as building up a data structure and then collapsing it to a single value. This is called a hylomorphism or refold. It's possible to elide the intermediate structure altogether for improved efficiency. hylo :: Functor f => (a -> f a) -> (f b -> b) ->...
Giving your list a type To create a list you need a type (any class, e.g. String). This is the type of your List. The List will only store objects of the specified type. For example: List<String> strings; Can store "string1", "hello world!", "goodbye", etc, b...
In SpriteKit a Sprite is represented by the SKSpriteNode class (which inherits from SKNode). First of all create a new Xcode Project based on the SpriteKit template as described in Your First SpriteKit Game. Creating a Sprite Now you can create a SKSpriteNode using an image loaded into the Assets...
// class declaration with a list of parameters for a primary constructor type Car (model: string, plates: string, miles: int) = // secondary constructor (it must call primary constructor) new (model, plates) = let miles = 0 new Car(model, plates, miles) ...
Open Xcode and select Create a new Xcode Project. Now select iOS > Application on the left and Game on the main selection area. Press Next. Write into Product Name the name of your first great game. Into Organization Name the name of your company (or simply your own name). Organisation I...
Let's say you have a User model class User < ActiveRecord::Base end Now to update the first_name and last_name of a user with id = 1, you can write the following code. user = User.find(1) user.update(first_name: 'Kashif', last_name: 'Liaqat') Calling update will attempt to update the gi...
If you are given a JSON string : val str = """{ | "name" : "Jsony McJsonface", | "age" : 18, | "hobbies" : [ "Fishing", "Hunting", "Camping" ], | "pet" : { | ...
C-style bit manipulation A bit can be set using the bitwise OR operator (|). // Bit x will be set number |= 1LL << x; Using std::bitset set(x) or set(x,true) - sets bit at position x to 1. std::bitset<5> num(std::string("01100")); num.set(0); // num is now 01101 ...
C-style bit-manipulation A bit can be cleared using the bitwise AND operator (&). // Bit x will be cleared number &= ~(1LL << x); Using std::bitset reset(x) or set(x,false) - clears the bit at position x. std::bitset<5> num(std::string("01100")); num.reset(2); ...
C-style bit-manipulation A bit can be toggled using the XOR operator (^). // Bit x will be the opposite value of what it is currently number ^= 1LL << x; Using std::bitset std::bitset<4> num(std::string("0100")); num.flip(2); // num is now 0000 num.flip(0); // num is n...
C-style bit-manipulation The value of the bit can be obtained by shifting the number to the right x times and then performing bitwise AND (&) on it: (number >> x) & 1LL; // 1 if the 'x'th bit of 'number' is set, 0 otherwise The right-shift operation may be implemented as either a...
To create a new Rails 5 API, open a terminal and run the following command: rails new app_name --api The following file structure will be created: create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app create app/as...
Abilities are defined in the Ability class using can and cannot methods. Consider the following commented example for basic reference: class Ability include CanCan::Ability def initialize(user) # for any visitor or user can :read, Article if user if user.admin? ...
When you implement java.io.Serializable interface to make a class serializable, the compiler looks for a static final field named serialVersionUID of type long. If the class doesn't have this field declared explicitly then the compiler will create one such field and assign it with a value which come...
Download the Atlassian conversion utility here. This utility requires Java, so please ensure that you have the Java Runtime Environment JRE installed on the machine you plan to do the conversion. Use the command java -jar svn-migration-scripts.jar verify to check if your machine is missing any of t...
To split a JID into its component parts (the localpart, domainpart, and resourcepart), the following algorithm should be used (where the localpart is represented by lp, the resourcepart by rp, and the domainpart by dp and ∈ is used to check if the given character is included in the string): Note ...
NSString *someString = @" Objective-C Language \n"; NSString *trimmedString = [someString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; //Output will be - "Objective-C Language" Method stringByTrimmingCharactersInSet returns a new str...
Object obj = new Object(); // Note the 'new' keyword Where: Object is a reference type. obj is the variable in which to store the new reference. Object() is the call to a constructor of Object. What happens: Space in memory is allocated for the object. The constructor Object() is call...
To receive a file uploaded via an HTTP Post, you need to do the following: @RequestMapping( value = "...", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE ) public Object uploadFile( @RequestPart MultipartFile file ) { String fileNam...

Page 48 of 137