Skip to content

Commit 8ddce4a

Browse files
committed
update IteratorPattern
1 parent 91fac65 commit 8ddce4a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

notebooks/IteratorPattern.ipynb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"source": [
2222
"## Design patterns\n",
2323
"\n",
24+
"- great resource on Refactoring, Design Patterns and Clean code - https://refactoring.guru/\n",
25+
"- design patterns are a formalized way of describing a solution to a problem\n",
2426
"- the analogy: engineers and architects designing to build bridges, towers, buildings, and physical structures\n",
2527
" - they follow certain principles to ensure structural integrity\n",
2628
"- design patterns are an attempt to bring this formal definition to software engineering\n",
@@ -663,7 +665,7 @@
663665
},
664666
{
665667
"cell_type": "code",
666-
"execution_count": 33,
668+
"execution_count": null,
667669
"id": "800548c6",
668670
"metadata": {},
669671
"outputs": [
@@ -686,6 +688,8 @@
686688
}
687689
],
688690
"source": [
691+
"# there's a file in the data directory called system.log\n",
692+
"# let's read it in using a generator expression\n",
689693
"! cat data/system.log"
690694
]
691695
},
@@ -733,14 +737,17 @@
733737
},
734738
{
735739
"cell_type": "code",
736-
"execution_count": 37,
740+
"execution_count": null,
737741
"id": "05760ea0",
738742
"metadata": {},
739743
"outputs": [],
740744
"source": [
741745
"with full_log_path.open() as source:\n",
746+
" # create a generator expression that will yield lines from the log file\n",
747+
" # that contain the word 'WARN'\n",
742748
" power_lines = (line for line in source if 'WARN' in line)\n",
743749
" with warn_log_path.open('w') as target:\n",
750+
" # iterate over the lines to write each line to the new file\n",
744751
" for line in power_lines:\n",
745752
" target.write(line)"
746753
]
@@ -775,7 +782,6 @@
775782
"\n",
776783
"- generator functions embody the essential features of a generator expression\n",
777784
" - which is the generalization of comprehension\n",
778-
"- use regular expression to parse lines into different columns of values\n",
779785
"- special functions that return an iterator which returns a stream of values\n",
780786
"- resumable functions that can retain local variable information to resume the function where it left off\n",
781787
"- uses `yield` keyword to yield the next value as opposed to `return`\n",

0 commit comments

Comments
 (0)