Git Product home page Git Product logo

nil-safe-send's Introduction

Nil-Safe-Send

Super minimalistic non-obtrusive utility to access nested models in a slimmer and arguably more legible manner, while maintaining debuggability.
Loosely inspired by the new Javascript language feature: "optional chaining"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

Examples

myArray := { 2. nil }.
myArray _ first _ squared _ * 12.   "=> prints 48"
myArray _ second _ squared _ * 12.   "=> prints nil"
myArray _ second _ squared * 12.   "=> raises an error"
myArray _ second _ squared isNil.  "=> prints true"

Installation

To install this library you clone this repository and load BaselineOfNilSafeSend. This can be done using the Iceberg UI tools and with the following script:

Metacello new
  baseline: 'NilSafeSend';
  repository: 'github://Ironirc/Nil-Safe-Send:main';
  load.

How it works

Sending and underscore to a receiver, just returns the receiver, or in case of nil, returns a special intermediary object.
This intermediary object is the sole instance of MessageSwallower (subclass of UndefinedObject). It's doesNotUnderstand returns nil.
This makes the effect very local and controllable

To be discussed

Is it ok to claim underscore '_' as global method name?

Todo

  • Look for better examples
  • More and better tests

nil-safe-send's People

Contributors

ironirc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.