Commit 9f305764 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+7 −0
Changes for Functional Programming with Python - Working Files/Chapter 1/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+7 −0
Changes for Functional Programming with Python - Working Files/Chapter 10/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+7 −0
Changes for Functional Programming with Python - Working Files/Chapter 2/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+7 −0
Changes for Functional Programming with Python - Working Files/Chapter 3/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+34 −0
Changes for Functional Programming with Python - Working Files/Chapter 4/core.py: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
from pyrsistent import PClass, pmap_field, field, pmap

class Location(PClass):
    name = field(str)
    description = field(str)
    exits = pmap_field(str, str)  # direction name -> location name

class GameState(PClass):
    location = field(Location)
    world = pmap_field(str, Location)

def render(state):
    exits = '\n'.join('* {} to {}'.format(exit, location)
                      for exit, location in state.location.exits.items())
    return "* {name} *\n\n{description}\n\nExits:\n{exits}".format(
        name=state.location.name,
        description=state.location.description,
        exits=exits
    )

def move(state, exit_name):
    location_name = state.location.exits.get(exit_name)
    if location_name is None:
        return None
    target_location = state.world.get(location_name)
    return GameState(location=target_location, world=state.world)


home = Location(name="Home", description="Home is where the heart is!",
                exits={'east': 'Street'})
street = Location(name="Street", description="The street next to your house.",
                  exits={'west': 'Home'})
world = pmap({x.name: x for x in [home, street]})
initial_state = GameState(location=home, world=world)
Loading