Working with Constants and iota in Go.
The Constant Generator iota
Here’s an example from the time package, which defines named constants of type Weekday for the days of the week, starting with zero for Sunday. Types of this kind are often called en...
In PHP, there are 3 ways to delete an element from an array.
Using unset Function
The unset(mixed $var, mixed ...$vars): void function destroys the specified variables. For example,
$arr = ["a", "b", "d"];
unset($arr[1]);
print_r($arr);
Arr...
In Python, there are 3 ways to get the position of a character.
Using find Method
The str.find(sub[, start[, end]]) method returns the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start an...
In Python, there are 2 ways to check if an object is of a given type.
Using isinstance Method
The isinstance(object, classinfo) method returns True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtua...
In Rust, there are 2 ways to index a string.
Using as_bytes Function
If the enum is C-like, then you can create a static array of each of the variants and return an iterator of references to them:
fn main() {
let s = "abc";
let b: u8 = s.as...
In Rust, there are 2 ways to iterate through the values of an enum.
Using a static array
If the enum is C-like, then you can create a static array of each of the variants and return an iterator of references to them:
use self::Direction::*;
use...
In Rust, there are 3 ways to iterate over a string by character.
Using chars Method
The chars() method returns an iterator over the chars of a string slice. See the following example:
fn main() {
let s = "abc";
for c in s.chars() {
pr...
In Rust, there are 3 ways to convert string to json.
Using Serde JSON
Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.
Adding dependencies
In Cargo.toml file we’ll add this information.
[de...
Generates and/or modifies files based on a schematic.Creates a new, generic NgModule definition in the given or default project.
NgModule
ng generate module page/edit
ng g m page/edit
CREATE src/app/page/edit/edit.module.ts (19...