Skip to content

Instantly share code, notes, and snippets.

@aritode
Forked from rondy/01_functional_objects.md
Created November 13, 2019 19:27
Show Gist options
  • Save aritode/df7d4a323d8b8d65c6edd53e8e123a71 to your computer and use it in GitHub Desktop.
Save aritode/df7d4a323d8b8d65c6edd53e8e123a71 to your computer and use it in GitHub Desktop.

Functional objects

  • Start with a verb;
  • Public contract is a #call method;
    • Enables SRP;
    • Enables composition;
    • Enables polymorphism;
    • Enables to receive Proc/callables objects;
  • Receive stateful/impure functions through the object initializer;
    • This permits easy mocking/substitution.
  • Receive pure function inputs through the #call method;
  • This resembles curry-like functions;
  • The #call calling always returns a value, preferably 'result'-like objects;
    • This avoids 'primitive obssesion' anti-pattern;
    • Consider monadics operations;
  • Define stateful/impure functions as default implementation, in case nothing is received;
  • Stateful/impure functions are always returned as closures/lambda;
    extract_utm_campaign_value_from(url) # is pure
    get_page_title.call(url)             # is impure
  • Consider to be event-driven;
  • Message passing is natural;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment