Skip to content

Commit

Permalink
add object support to pluck
Browse files Browse the repository at this point in the history
  • Loading branch information
gkz committed Jun 12, 2012
1 parent 7347cb0 commit b797bd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion prelude.ls
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ exports.find = find = (f, xs) -->
void

exports.pluck = pluck = (prop, xs) -->
[x[prop] for x in xs when x[prop]?]
if typeof! xs is \Object
then {[key, x[prop]] for key, x of xs when x[prop]?}
else [x[prop] for x in xs when x[prop]?]

exports.head = head = (xs) ->
return void if not xs.length
Expand Down
4 changes: 3 additions & 1 deletion test.ls
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ eq 2, find (==2), {a:1, b:2}

# pluck
eq 'one,two' "#{ pluck \num [num: \one; num: \two] }"

plucked = pluck \num {a: {num: 1}, b: {num: 2}}
eq 1 plucked.a
eq 2 plucked.b

list = [1 2 3 4 5]
string = 'abcde'
Expand Down

0 comments on commit b797bd3

Please sign in to comment.