No kind of object does what you want.
You cannot do   3 3
or                      #x #y
As for [:x | x + 1] 3, what would be the *point* of doing this?
What is the block suppose to *do* with the 3?  Do you want to extend this
to [:x :y | x + y] 3 4 ?  If not, why not?  What about [3+4] "what to put here?"
As for composition, my own library has
 ( [:x | x + 1] before: [:y | y * 2] ) value: 10   => 22
 ( [:y | y * 2] after: [:x | x + 1] ) value: 10 => 22
with no magic syntax needed.
The |> operator in F# has been imitated in several other languages.
I've implemented it in my Smalltalk, and tested it, but never bothered to use
it.

Object
  methods for: 'combinators'
    |> unary
      ^(unary isMemberOf: NiladicSelector) "isKindOf: Symbol"
         ifTrue:  [unary send_to: self]    "self perform: unary"
         ifFalse: [unary value: self]

MonadicBlock
  methods for: 'invoking'
    collect
      ^[:collection | collection collect: self]

    do
      ^[:collection | collection      do: self]

    reject
      ^[:collection | collection  reject: self]

    select
      ^[:collection | collection  select: self]

NiladicSelector
  methods for: 'invoking'
    collect
      ^[:collection | collection collect: [:each | each perform: self]]

    do
      ^[:collection | collection      do: [:each | each perform: self]]

    reject
      ^[:collection | collection  reject: [:each | each perform: self]]

    select
      ^[:collection | collection  select: [:each | each perform: self]]

10 |> [:x | x+1] |> [:y | y*2]  ==> 22
#(1 2 3) |> [:x | x * 10] collect => #(10 20 30)

Reply via email to