From 6cf1a813675829195348683aeb8c602011784789 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 8 May 2019 14:09:42 -0500 Subject: [PATCH] Add new useful facilities to Function --- lib/dhall/ast.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/dhall/ast.rb b/lib/dhall/ast.rb index f70cd92..aa495fe 100644 --- a/lib/dhall/ast.rb +++ b/lib/dhall/ast.rb @@ -157,7 +157,8 @@ module Dhall end end - def call(*args) + def call(*args, &block) + args += [block] if block args.map! { |arg| arg&.as_dhall } return super if args.length > 1 @@ -168,6 +169,29 @@ module Dhall end alias [] call + alias === call + + def <<(other) + FunctionProxy.new( + ->(*args, &block) { call(other.call(*args, &block)) }, + curry: false + ) + end + + def >>(other) + FunctionProxy.new( + ->(*args, &block) { other.call(call(*args, &block)) }, + curry: false + ) + end + + def binding + to_proc.binding + end + + def curry + self + end def as_json if var == "_" -- 2.45.2