jeremykohn / functional-javascript Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/functional-javascript
Automatically exported from code.google.com/p/functional-javascript
An application which calls Functional methods with lambda strings, rather
than verbosely-declared functions, will result in a lot of calls to
`string.lambda()`. However, at present each call to `lambda()` represents
an invocation of the javascript runtime compiler, whether or not the string
has been converted into a function already in a previous call.
I suggest caching the output of `string.lambda()` for equivalent inputs,
thereby (hopefully) improving performance by minimizing recompilation. A
modified version of `String.prototype.lambda`, including a small caching
facility, is attached.
Original issue reported on code.google.com by [email protected]
on 7 Aug 2007 at 6:02
Attachments:
What steps will reproduce the problem?
1. execute load('functional.js') from within Rhino
What is the expected output? What do you see instead?
I expect no output, no exceptions. But instead, we get an exception because
the "window" global is not defined.
Changing the top of the source to read:
var window;
var Functional = (window && window.Functional) || {};
Fixes the problem.
Original issue reported on code.google.com by [email protected]
on 13 Sep 2007 at 2:50
What version of the product are you using? On what operating system?
-- This is the version on osteele.com as of this morning.
Please provide any additional information below.
...just like I and K are in Functional. But at least the docs and the code
are consistent.... (-:
Original issue reported on code.google.com by [email protected]
on 2 Nov 2007 at 6:13
In many of the functions, the 'apply' function is used and has an explicit
array passed as the second argument, like this snippet from 'foldr':
result = fn.apply(object, [sequence[i], result]);
There is no reason to use 'apply' here - you should use 'call' when you know
how many arguments you're passing ahead of time. Lines like the above should
instead be:
result = fn.call(object, sequence[i], result);
'call' is much faster than 'apply', and clearer.
Original issue reported on code.google.com by [email protected]
on 27 Dec 2011 at 11:16
Hey Oliver, Jeremy Ashkenas mentioned to me that this might be of interest to
you for functional.js. What do you think? is this something you'd be interested
in? (I've already written it)
would a map function like this be valuable?
{{{
// Used to map over fields in various parts of the object hierarchy
// all in one step. most useful when you receive an API response
// where all values are strings (but should be ints, dates, bools etc).
//
// Any value that ends with "[]" (ex. photo_ids[] - you know... like
// an empty array index) indicates the value is an array and that it
// should be iterated over.
//
// Example:
_.deepMap(obj, [
"UserID",
"profile.photos[].ID",
"profile.lucky_numbers[]"
], function(val) {
return parseInt(val);
});
}}}
The example takes something like
{{{
obj = {
UserID: "15",
profile: {
photos: [
{name: "dog", ID: "13"},
{name: "cat", ID: "18"}
]
lucky_numbers: ["15", "7", "21"]
}
}
}}}
and gives you back:
{{{
obj = {
UserID: 15,
profile: {
photos: [
{name: "dog", ID: 13},
{name: "cat", ID: 18}
]
lucky_numbers: [15, 7, 21]
}
}
}}}
I use it pretty often to convert the data in xml responses from an API to
useful data types.
Original issue reported on code.google.com by [email protected]
on 24 Nov 2010 at 5:03
Hi,
I'm obsessed with this library. It's been a joy to use and has revolutionized
the way i write code. Seriously.
I know it may not translate very well, but I would love to try and recreate
this point-free example from the tacit programming wikipedia
(http://en.wikipedia.org/wiki/Tacit_programming):
// pointfree
mf = (. map) . (.) . filter
// pointfull
mf criteria operator list = filter criteria (map operator list)
Is there a way this is possible?
Original issue reported on code.google.com by [email protected]
on 19 Mar 2012 at 3:30
This library provides a lot of great stuff for lists, but next to nothing for
objects. But an object is not so different from a list. They're both
associative arrays, but when you iterate through an object you care what
the key names are as well as the values.
I want to run map on an object like it's an associative array. That is, I want
to do something like python's iteritems()
What is the expected output? What do you see instead?
I expected to be able to do is this:
map('value key -> {key:key, value:value}', {a:"foo", b:5})
# -> [{key:"a", value:"foo"}, {key:"b", value:5}]
Unfortunately, this actually returns [undefined]
I think it should be made to work, though, because it already works for
normal lists:
map('value key -> {key:key, value:value}', ["foo", 5])
# -> [{key:0, value:"foo"}, {key:0, value:5}]
Alternatively, if you want to preserve the counter functionality of the
second argument, you could make the real key name be the third
argument, like so:
map('value counter key -> {key:key, value:value}', {a:"foo", b:5})
# -> [{key:"a", value:"foo"}, {key:"b", value:5}]
What version of the product are you using? On what operating system?
1.0.2 in Safari 4 and Chrome 4 for Mac.
Please provide any additional information below.
The main reason I bring this up is, since your library doesn't contain any
object iterators, I decided to include underscore.js in my project as well.
Unfortunately, functional.js seems to break underscore.js -- when I include
it, it kills the underscore identifier underscore.js uses. You may file this
as
an additional bug.
I wanted to use underscore.js for its _.keys(object) and _.values(object)
methods. I proposed they add _.items(object) as well. I suppose I could
implement these myself though, since they're rather simple, but this does
seem in the problem domain of this library.
Original issue reported on code.google.com by [email protected]
on 19 Jan 2010 at 9:03
I can't find a mailinglist or anything, so I'm just adding this here (and
private email)
commit 63b15fc9105e0df211e0b813314ff15d965559ea
Author: Randy Robertson <rmrobert <a|t> vmware __dot__ com>
Date: Fri Apr 30 15:43:59 2010
Fix usage of pluck
diff --git a/functional.min.js b/functional.min.js
index a0225f0..aeb7a89 100644
--- a/functional.min.js
+++ b/functional.min.js
@@ -34,7 +34,7 @@ Functional.invoke=function(methodName){var
args=Array.slice(arguments,1);return
Functional.pluck=function(name){return function(object){return
object[name];}}
Functional.until=function(pred,fn){fn=Function.toFunction(fn);pred=Functio
n.toFunction(pred);return function(value){while(!pred.call(null,value))
value=fn.call(null,value);return value;}}
-Functional.zip=function(){var
n=Math.min.apply(null,Functional.map('.length',arguments));var results=new
Array(n);for(var i=0;i<n;i++){var
key=String(i);results[key]=Functional.map(pluck(key),arguments);};return
results;}
+Functional.zip=function(){var
n=Math.min.apply(null,Functional.map('.length',arguments));var results=new
Array(n);for(var i=0;i<n;i++){var
key=String(i);results[key]=Functional.map(Functional.pluck(key),arguments);
};return r
Functional._startRecordingMethodChanges=function(object){var
initialMethods={};for(var name in object)
initialMethods[name]=object[name];return{getChangedMethods:function(){var
changedMethods={};for(var name in object)
if(object[name]!=initialMethods[name])
Original issue reported on code.google.com by [email protected]
on 3 May 2010 at 9:10
The CommonJS module system defines an 'exports' object. Only values assigned as
properties of this object return to the calling context (the caller and the
called don't share a scope).
If you try to use Functional.js from a CommonJS-using system it won't work. I
discovered this when trying to load Functinonal.js into my Node.js application.
Applying the following amendment to the Functional.js file would return the
Functional and Function.prototype objects to the calling scope. The caller can
then mix the Function.prototype object into Function.prototype in the calling
scope.
>>
//
// CommonJS:
// Export Functional & Function if an exports object is detected.
//
if (typeof exports === 'object') {
exports.Functional = Functional;
exports.FunctionPrototype = Function.prototype;
}
<<
Functional.js is great by the way, Thanks a lot!
Dom
Original issue reported on code.google.com by [email protected]
on 11 Oct 2010 at 2:37
What steps will reproduce the problem?
1. Start Rhino Console
2. load("env.js","functional.js"); <-- env.js is DOM curtain for Rhino
3. ">2".toFunction();
What is the expected output? What do you see instead?
js: "functional.js#886(Function)", line 1: uncaught JavaScript runtime
exception: SyntaxError: missing formal parameter
js: function anonymous(['$1']) {return ($1>2)}
js: ...................^
Expected:
"function anonymous($1) {
return $1 > 2;
}"
What version of the product are you using? On what operating system?
OS X, JVM 1.5, functional.js version: 1.0.1
Please provide any additional information below.
String.toFunction returns
function () {
return this;
}
And String.prototype.toFunction returns
function () {
var body = this;
if (body.match(/\breturn\b/)) {
return new Function(this);
}
return this.lambda();
}
which looks right.
This means the attached property toFunction() is used by Rhino instead of
the prototype chain.
It'd be great if this worked in rhino. javascript is fast becoming my
favourite language for scripting everything.
Original issue reported on code.google.com by [email protected]
on 25 Sep 2007 at 2:15
map takes three arguments... iterator, sequence, object
but in functional programming we want to call our functions with the data last.
in this case sequence is our data, so why not place object before sequence?
Original issue reported on code.google.com by [email protected]
on 16 Jul 2014 at 8:35
At the demo page
http://osteele.com/sources/javascript/functional/
enter
map('1-foobar', [2, 3])
and the result is
[-1, -2]
I am not sure if this is a defect of only the demo page, or the library
itself.
Assuming there is no easy fix to the demo page, I would say currying is
broken. The simplest thing would be to disallow currying, and only allow
constructions like
map (function (a) {return a + 1;}, [2,3]);
Otherwise you have to fix currying to do something sane.
This was pointed out to me by rhoomba at
http://programming.reddit.com/info/2u5tz/comments/c2u8ln
Original issue reported on code.google.com by [email protected]
on 27 Sep 2007 at 9:22
What steps will reproduce the problem?
1. from: http://osteele.com/sources/javascript/functional/
change example box: map('10+', [2, 32]) this works fine, but map('10+', [2,
032]) does not.
What is the expected output? What do you see instead?
should see 42 for the second value, it returns 36 when using a leading zero. I
tested using a single digit value and it returned the correct values for all
leading zero cases (from single to many), but once I used a 2 (or more) digit
number, it began to exhibit the anomoly.
What version of the product are you using? On what operating system?
The one in the example above. Chrome 19.0.1084.46 m, Win 7 (64bit).
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 21 May 2012 at 6:28
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.