{"action":"closed","issue":{"url":"https://api.github.com/repos/ZachBray/FunScript/issues/149","labels_url":"https://api.github.com/repos/ZachBray/FunScript/issues/149/labels{/name}","comments_url":"https://api.github.com/repos/ZachBray/FunScript/issues/149/comments","events_url":"https://api.github.com/repos/ZachBray/FunScript/issues/149/events","html_url":"https://github.com/ZachBray/FunScript/issues/149","id":50832780,"number":149,"title":"Applying directly lambdas containing just a call","user":{"login":"alfonsogarciacaro","id":8275461,"avatar_url":"https://avatars.githubusercontent.com/u/8275461?v=3","gravatar_id":"","url":"https://api.github.com/users/alfonsogarciacaro","html_url":"https://github.com/alfonsogarciacaro","followers_url":"https://api.github.com/users/alfonsogarciacaro/followers","following_url":"https://api.github.com/users/alfonsogarciacaro/following{/other_user}","gists_url":"https://api.github.com/users/alfonsogarciacaro/gists{/gist_id}","starred_url":"https://api.github.com/users/alfonsogarciacaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfonsogarciacaro/subscriptions","organizations_url":"https://api.github.com/users/alfonsogarciacaro/orgs","repos_url":"https://api.github.com/users/alfonsogarciacaro/repos","events_url":"https://api.github.com/users/alfonsogarciacaro/events{/privacy}","received_events_url":"https://api.github.com/users/alfonsogarciacaro/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-12-03T12:45:53Z","updated_at":"2015-02-17T11:04:05Z","closed_at":"2015-02-17T11:04:05Z","body":"Hi @ZachBray!\r\n\r\nAfter we talked about improving the compiler so it works better with JS optimizers like Google closure, I've been thinking that one of the biggest problems are the F# pipelines. In the JS code, they end up as chains of lambdas containing just one method call, which is not very readable and likely nor performant. For example ```5 |> (+) 3 |> (-) 1 |> abs |> ignore``` becomes:\r\n\r\n```\r\n    var _x = 1;\r\n    var __x = 3;\r\n    (function(value)\r\n    {\r\n      var ignored0 = value;\r\n    })((function(value)\r\n    {\r\n      return MathJS__Abs$(value);\r\n    })((function(_y)\r\n    {\r\n      return (_x - _y);\r\n    })((function(_y)\r\n    {\r\n      return (__x + _y);\r\n    })(5))));\r\n```\r\n\r\nI've been trying to find the way to apply the lambdas directly in these cases before the JS compilation. And I came up with the following:\r\n\r\n```\r\nmodule internal FunScript.LambdaApplication\r\n\r\nopen AST\r\nopen Microsoft.FSharp.Quotations\r\n\r\nlet private application =\r\n   CompilerComponent.create <| fun (|Split|) _ returnStategy ->\r\n      function\r\n\r\n// NEW PATTERNS\r\n      | Patterns.Application(Patterns.Lambda(var, Patterns.Call(callOwner, call, callArgs)), lambdaArg) ->\r\n        let args = callArgs |> List.map (function\r\n            | Patterns.Var v when v.Name = var.Name -> lambdaArg\r\n            | _ as a -> a)\r\n        match callOwner with\r\n        | Some owner -> compiler.Compile returnStrategy <| Expr.Call(owner, call, args)\r\n        | None -> compiler.Compile returnStrategy <| Expr.Call(call, args)\r\n\r\n      | Patterns.Application(Patterns.Let(letVar, letVarValue, Patterns.Lambda(lambdaVar, Patterns.Call(callOwner, call, callArgs))), lambdaArg) ->\r\n        let args = callArgs |> List.map (function\r\n            | Patterns.Var v when v.Name = letVar.Name -> letVarValue\r\n            | Patterns.Var v when v.Name = lambdaVar.Name -> lambdaArg\r\n            | _ as a -> a)\r\n        match callOwner with\r\n        | Some owner -> compiler.Compile returnStrategy <| Expr.Call(owner, call, args)\r\n        | None -> compiler.Compile returnStrategy <| Expr.Call(call, args)\t\r\n\r\n// PREVIOUS PATTERNS COME HERE\r\n```\r\n\r\nWith this the previous sample would become simply ```var ignored0 = MathJS__Abs$((1 - (3 + 5)));```. However, I'm sure there's a cleaner way to do this and unfortunately there were many tests failing after making this change (and thus I didn't commit it).\r\n\r\nDo you have any ideas?\r\n\r\nCheers,\r\nAlfonso\r\n\r\n"}}