Skip to content

Instantly share code, notes, and snippets.

@pixelhandler
Last active January 18, 2018 23:06
Show Gist options
  • Select an option

  • Save pixelhandler/7e59f545a12cb6b95957f02a133f2d18 to your computer and use it in GitHub Desktop.

Select an option

Save pixelhandler/7e59f545a12cb6b95957f02a133f2d18 to your computer and use it in GitHub Desktop.
Notes from a talk at Ember LA meetup on the topic of using a Maybe type and learning it via TDD of a bowling game.

Links from talk, Bowling with Monads

  • A practical example of TDDing a bowling game then refactoring to safely use undefined (& killing null too) with a "Maybe/Optional" type (a Monad).
  • About the game, Bowling 101

The source code

  • TDD bowling solution using a Maybe on branch safe-undefined, see README.

Maybe source code, See notes in comments

Tests for Maybe type which show how it works... how to operate on values in a container type. See the tests using .map, .chain, and .ap

Bowling game src code and tests using the Maybe type. See the roll function and frame function which use a Maybe; and notice that the scoring functions operate on the values contained in the Maybe.

There are some functional programing utilities methods here, for partial application and currying.

Learning a Maybe

Libraries:

Functional programming:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment