summaryrefslogtreecommitdiff
path: root/topics/maybe-monad.gmi
diff options
context:
space:
mode:
Diffstat (limited to 'topics/maybe-monad.gmi')
-rw-r--r--topics/maybe-monad.gmi13
1 files changed, 7 insertions, 6 deletions
diff --git a/topics/maybe-monad.gmi b/topics/maybe-monad.gmi
index b748ad5..d6f87f2 100644
--- a/topics/maybe-monad.gmi
+++ b/topics/maybe-monad.gmi
@@ -37,15 +37,16 @@ foo.map(lambda x: 1 + x) \
Finally, let's put all this together in a practical example using sql_query_mdict from genenetwork. Consider the following code using the DictCursor. The column foo may contain NULL values, and we need to check for them.
```
-with conn.cursor(MySQLdb.cursors.DictCursor) as cursor:
- cursor.execute("SELECT foo FROM bar")
- for row in cursor.fetchall():
- if row["foo"] is not None:
- print(row["foo"])
+with database_connection() as conn:
+ with conn.cursor(MySQLdb.cursors.DictCursor) as cursor:
+ cursor.execute("SELECT foo FROM bar")
+ for row in cursor.fetchall():
+ if row["foo"] is not None:
+ print(row["foo"])
```
But, with sql_query_mdict, the row object is a MonadictDict where all values are monadic. We therefore do not need any special conditional checks.
```
-with database_connection() as conn
+with database_connection() as conn:
for row in sql_query_mdict(conn, "SELECT foo FROM bar"):
row["foo"].bind(print)
```