- Pattern match.
- Keep consistent level of abstraction per function.
- Don't mix pure functions with IO functions. Segregate.
- Build upon ubiquituous domain language.
- Define Interfaces for service layer around infrastructure and application.
- Partial function composition == Dependency Injection. But it is not a preferred functional pattern.
- Don't YAGNI
- If you find yourself passing parameters and adding conditional..the abstraction is incorrect.
- Build upon these foundational low-level architectural design patterns:
- Value objects, Business Domains, Service Layers
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
# naive solution | |
class Solution: | |
POS_NUM = 1000 | |
def removeDuplicates(self, nums: List[int]) -> int: | |
start = 0 | |
n = len(nums) | |
end = n - 1 | |
for start in iter(lambda: start, end): | |
if start > end: | |
break |
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
NATO_BAG = { | |
'A': 'Alpha', | |
'B': 'Bravo', | |
'C': 'Charlie', | |
'D': 'Delta', | |
'E': 'Echo', | |
'F': 'Foxtrot', | |
'G': 'Golf', | |
'H': 'Hotel', | |
'I': 'India', |
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
# Definition for a binary tree node. | |
# | |
# defmodule TreeNode do | |
# @type t :: %__MODULE__{ | |
# val: integer, | |
# left: TreeNode.t() | nil, | |
# right: TreeNode.t() | nil | |
# } | |
# defstruct val: 0, left: nil, right: nil | |
# 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
class Solution: | |
def subsets(self, nums: List[int]) -> List[List[int]]: | |
def do_generate(result, slate, subset): | |
result += [slate] | |
for idx, num in enumerate(subset): | |
new_subset = subset[idx+1:] | |
do_generate(result, slate + [num], new_subset) | |
return result | |
return do_generate([], [], nums) | |
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
def find_combinations(n, k): | |
""" | |
Args: | |
n(int32) | |
k(int32) | |
Returns: | |
list_list_int32 | |
""" | |
array = list(range(1,n+1)) | |
result = set() |
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
def fib(n): | |
# print(f"for fib {n}") | |
a, b = 0, 1 | |
if n == a: return a | |
if n == b: return b | |
return do_fib(n-1, b, a+b) | |
def do_fib(n, /, a=0, b=1): | |
if n == 0: return a |
- Design in isolation (Partition)
- 2 business modules must communicate over message pattern. They are not considered business modules if one requires the other, in which case they don’t need to communicate over messages if a business process has to die, all interconnected business modules must die
- process are stateless
- fault tolerant implies scalability implies concurrency and concurrent business processes
- Availability
- its better to die on fault and restart, then drag and build up the pile of error
- when a process dies, fault detection and communicating fault is important
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
defmodule ToHex do | |
@hex_base 16 | |
def to_hex(0), do: 0 | |
def to_hex(num) when is_number(num) do | |
div(num, @hex_base) | |
|> IO.inspect | |
|> then(& {to_hex(&1), rem(num, @hex_base)}) |
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
x = [1,2,3] | |
if len(x) < 3: | |
return x | |
else: | |
return [4,5,6] |
NewerOlder