Skip to content

Instantly share code, notes, and snippets.

View maryrosecook's full-sized avatar

Mary Rose Cook maryrosecook

View GitHub Profile
bands = [{'name': 'sunset rubdown', 'country': 'UK', 'active': False},
{'name': 'women', 'country': 'Germany', 'active': False},
{'name': 'a silver mt. zion', 'country': 'Spain', 'active': True}]
def assoc(_d, key, value):
from copy import deepcopy
d = deepcopy(_d)
d[key] = value
return d
def zero(s):
if s[0] == "0":
return s[1:]
def one(s):
if s[0] == "1":
return s[1:]
"""
def rule_sequence(s, rules):
people = [{'name': 'Mary', 'height': 160},
{'name': 'Isla', 'height': 80},
{'name': 'Sam'}]
"""
height_total = 0
height_count = 0
for person in people:
if 'height' in person:
height_total += person['height']
# Unfunctional version:
names = ['Mary', 'Isla', 'Sam']
'''
for i in range(len(names)):
names[i] = hash(names[i])
print names # => [6306819796133686941, 8135353348168144921, -1228887169324443034]
'''
@maryrosecook
maryrosecook / laurenprogram2.py
Created November 29, 2014 02:04
Lauren's second program
# shopping_list = ["apple", "toothbrush", "banana", "black lava"]
# shopping_list.append("cheese")
# shopping_list.reverse()
# print("Shopping List")
# for shopping_list_item in shopping_list:
# if len(shopping_list_item)<7 or shopping_list_item=="black lava":
# print("-" + shopping_list_item)
# if (shopping_list_item.get("done")==False):
# print ("-" + shopping_list_item.get("name"))
# else:
@maryrosecook
maryrosecook / gist:7cca0b83b896ade99f69
Created November 16, 2014 16:10
Lauren's first program!
shopping_list = ["apple", "toothbrush", "banana", "black lava"]
shopping_list.append("cheese")
shopping_list.reverse()
print("Shopping List")
for shopping_list_item in shopping_list:
if len(shopping_list_item)<7 or shopping_list_item=="black lava":
print("-" + shopping_list_item)
### Keybase proof
I hereby claim:
* I am maryrosecook on github.
* I am maryrosecook (https://keybase.io/maryrosecook) on keybase.
* I have a public key whose fingerprint is 59DB 7EF4 2BAC 5D67 22FB F7DA 7DFF 4628 A3F1 83AF
To claim this, I am signing this object:
# A practical introduction to functional programming
Many functional programming articles teach abstract functional techniques. That is, composition, pipelining, higher order functions. This one is different. It shows examples of imperative code that people write every day and translates them to a functional style.
The imperative examples are all loops. The first section of the article takes short, data transforming loops and translates them into functional maps and reduces. The second section takes longer loops, breaks them up into units and makes each unit functional. The third section takes a loop that is a long series of successive data transformations and decomposes it into a functional pipeline.
The examples are in Python, because many people find Python easy to read. A number of the examples eschew pythonicity in order to demonstrate functional techniques common to many languages: map, reduce, pipeline.
## A guide rope
block_size = 16
blocks = []
a_size = 128
b_size = 32
a = [0, 1, 2]
b = [0, 1, 2]
print a == b
def memoise(fn):