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
type UserModel struct { | |
} | |
// UserModel をレシーバとして関数を定義 | |
func (d *UserModel) CreateUser(user UserInformation) { | |
// DBAccessor を直接インスタンス化 | |
dba := DBAccessor.New() | |
dba.InsertUser(user.User) | |
dba.InsertUserEmail(user.Email) | |
} |
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
type mockDBAccessor struct { | |
} | |
func (m mockDBAccessor) InsertUser(user User) { | |
} | |
func (m mockDBAccessor) InsertUserEmail(email UserEmail) { | |
} | |
func TestCreateUser(t *testing.T) { |
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 が依存するクラスの *インターフェース* を全て指定 | |
type UserModel struct { | |
dba DBAccessorIface | |
} | |
// UserModel をレシーバとして関数を定義 | |
func (d *UserModel) CreateUser(user UserInformation) { | |
d.dba.InsertUser(user.User) | |
d.dba.InsertUserEmail(user.Email) | |
} |
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
expect_any_instance_of(DBAccessor).to receive(:insert_user).and_return("Success") | |
expect_any_instance_of(DBAccessor).to receive(:insert_user_email).and_return("Success") | |
UserModel.new.create_user(user_information) |
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
class UserModel | |
def create_user(user_information) | |
dba = DBAccessor.new | |
dba.insert_user(user_information.user) | |
dba.insert_user_email(user_information.email) | |
end | |
end |
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 std::io; | |
fn solve(line: &String, s: usize, t: usize) -> u32 { | |
if line.as_bytes()[s] != b'[' { | |
return line[s..t].parse::<u32>().unwrap() / 2 + 1 | |
} | |
let mut children = Vec::new(); | |
let mut i = s; | |
while i < t { | |
let ns = i + 1; |
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
{-# LANGUAGE ExistentialQuantification #-} | |
-- C1 :> C2 :> C3 | |
class C1 a where | |
f1 :: a -> String | |
class (C1 a) => C2 a where | |
f2 :: a -> String | |
class (C2 a) => C3 a where | |
f3 :: a -> String | |
data D1 = D1 -- instance of C1 |
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
type Zero = 0 | |
type Num = Zero | { 0: Num } | |
const any: any = null | |
function succ<T>(v: T): { 0: T } { | |
return any | |
} | |
type FizzNum = Zero | {0:{0:{0: FizzNum }}} |
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
type T = 1 | |
type F = 0 | |
function nand(v1: T, v2: T): F; | |
function nand(v1: T, v2: F): T; | |
function nand(v1: F, v2: T): T; | |
function nand(v1: F, v2: F): T; | |
function nand(v1, v2) { | |
return 0 // dummy | |
} |
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
// compile: tsc src.ts --lib es2017,dom -t es2015 | |
// 1. Async/Await | |
async function concatPromises(): Promise<string> { | |
const v0 = getValue() | |
const v1 = await getPromise1() | |
const v2 = await getPromise2() | |
return v0 + v1 + v2 | |
} | |
concatPromises().then(console.log) //=> Value: helloworld |
NewerOlder