This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MyStruct { /* ... */ } | |
impl MyStruct { | |
pub fn instance_method(&self) { /* ... */ }; | |
} | |
// usage | |
let my_struct = MyStruct { /* ... */ } | |
my_struct.instance_method(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user_model.rs | |
struct UserModel { /* ... */ } | |
impl UserModel { | |
pub fn fullname() -> String; | |
// ... | |
} | |
// happy_birthday_service.rs | |
pub fn send_message(session_context: &SessionContext, /* ... */) { | |
let message = session_context.user.happy_birthday_message(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UserModel.ts | |
type UserModel = { /* ... */ } | |
namespace UserService { | |
function fullName(): string { /* ... */ }; | |
// ... | |
} | |
// HappyBirthdayService.ts | |
function sendMessage(sessionContext: &SessionContext) { | |
let message = happyBirthdayMessage(sessionContext.user); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// consuming `apply_move` immutably | |
let chess_state = Chess::starting_board(); | |
let player_move = Move { start: ('G', 1), end: ('F', 3) }; | |
let next_state = { | |
let mut next_state = chess_state.clone(); | |
next_state.apply_move(player_move); | |
next_state | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mutations are explicitly opt in | |
let mut chess_game = Chess::starting_board(); | |
let player_move = Move { start: ('G', 1), end: ('F', 3) }; | |
chess_game.apply_move(player_move); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use serde::{Serialize, Deserialize}; | |
#[derive(Serialize, Deserialize)] | |
pub enum PlayerSide { /* ... */ } | |
#[derive(Serialize, Deserialize)] | |
pub struct Move { /* ... */ } | |
#[derive(Serialize, Deserialize)] | |
pub struct Board { /* ... */ } | |
#[derive(Serialize, Deserialize)] | |
pub struct Chess { board: Board, turn: PlayerSide } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum PlayerSide { /* ... */ } | |
type Move = { /* ... */ } | |
type Board = { /* ... */ } | |
type Chess = { board: Board; turn: PlayerSide } | |
namespace ChessService { | |
// functions for interacting with the game chess | |
function applyMove(chess: Chess, move: Move): Chess { /* ... */ } | |
function starting_state(): Chess { /* ... */ } | |
function listValidMoves(board: Chess, playerTurn: PlayerSide): Move[] { /* ... */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jscodeshift from "jscodeshift"; | |
import fs from "fs"; | |
import path from "path"; | |
const projectDirectory = "my/project/root/directory"; | |
/////////////////////////////////////////////////////////////////////////////// | |
// util functions | |
/////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {getSourceFilesIterator, lsFiles} from "react-codestats"; | |
const sourceFileIterator = getSourceFilesIterator("~/flexport/javascripts", { | |
extensions: ["js", "jsx"], | |
withParser: "flow", | |
}); | |
let formulaOneImports = 0; | |
let formComponentImports = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import iconNames from "latitude/iconNamesEnum"; | |
import {getSourceFilesIterator} from "react-codestats"; | |
const sourceFileIterator = getSourceFilesIterator("~/flexport/javascripts", { | |
extensions: ["js", "jsx"], | |
withParser: "flow", | |
}); | |
const iconUsageCounts = iconNames.reduce((acc, iconName) => { | |
acc.set(iconName, 0); |
NewerOlder