Skip to content

Instantly share code, notes, and snippets.

@toorosan
Created April 7, 2019 05:57
Show Gist options
  • Save toorosan/b69fee41c26521b676c046e716b9089d to your computer and use it in GitHub Desktop.
Save toorosan/b69fee41c26521b676c046e716b9089d to your computer and use it in GitHub Desktop.

Revisions

  1. toorosan created this gist Apr 7, 2019.
    26 changes: 26 additions & 0 deletions patterns.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    // Chained functions.
    type Chained struct {
    someUpdatedValue string
    }

    // ModifyFunction1 makes concatenation of someUpdatedValue and s, divided by "+"
    func (c Chained) ModifyFunction1(s string) Chained {
    return Chained{someUpdatedValue: c.someUpdatedValue + "+" + s}
    }

    // ModifyFunction2 makes concatenation of someUpdatedValue and s, divided by "-"
    func (c Chained) ModifyFunction2(s string) Chained {
    return Chained{someUpdatedValue: c.someUpdatedValue + "-" +s}
    }

    // String makes returns someUpdatedValue, helper for printing.
    func (c Chained) String() string {
    return c.someUpdatedValue
    }

    // ChainedExample provides example of usage for chained functions.
    func ChainedExample(initialValue string) Chained {
    return Chained{initialValue}.
    ModifyFunction1("ModifyFunction1").
    ModifyFunction2("ModifyFunction2")
    }