On 8/19/06, Chris Nokleberg <[EMAIL PROTECTED]> wrote:
>
>
> Bob Ippolito wrote:
> > I never really had any use cases for values without items. Do you have any?
>
> The primary one is when using an object as a set. The keys are some
> unique string derived from the object, but the actual objects are the
> values.

Well, there's map(itemgetter(1), items(obj)). You could make a
convenience function for that in your code with this:

values = partial(map, itemgetter(1));

> >> On 8/19/06, Chris Nokleberg wrote:
> >> 3) Similarly, a way to reverse the effect of Base.items is useful.
> > This we could use. I don't know about the extra map functions though.
>
> Sounds good. It might also be useful to have a method to build an
> object from separate keys and values arrays (zipobj?). mapValues could
> then also be written as
>
>   function mapValues(fn, obj) {
>     return zipobj(keys(obj), map(fn, values(obj)));
>   }

That would be a really bad implementation because IIRC there's no
ordering guarantee for property iteration, so you could end up with a
nonsense result here... it'd be better to just write a function that
deals with items.

I do agree that we should have a function that can create an object
from items style output though. I guess there would be a setItems(obj,
[item...]) and fromItems([item...]) where fromItems = partial(null,
setItems).

> Perhaps building an object from an array with alternating keys and
> values would be more pythony (if python is like perl), but this seems a
> little more useful.

Python is definitely not like Perl. That layout for key/value pairs
never ever shows up, it's always a list of 2-tuples (generalized to
all sequences, mostly). This is a pretty common layout, at least with
the languages that I've used recently.

Python:
>>> {"a": 1, "b": 2}.items()
[('a', 1), ('b', 2)]

Ruby:
irb(main):001:0> ({"a" => 1, "b" => 2}).entries
=> [["a", 1], ["b", 2]]

Erlang:
1> dict:to_list(dict:from_list([{a, 1}, {b, 2}])).
[{a,1},{b,2}]

> p.s. the link to "zip" from "map" in the docs goes nowhere

Fixed in [1082].

-bob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to