Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 55 additions and 6 deletions.
  1. +25 −3 spec/gtl_spec.coffee
  2. +30 −3 src/gtl.coffee
View
28 spec/gtl_spec.coffee
@@ -143,9 +143,31 @@ describe 'Greater than less', ->
['storm we are ill', 'is we ill yo', 'trololo will']
).should.eql ['is we ill yo']
- it 'should merge curried rules with passed by user'
-
- it 'should curry iterator'
+ it 'should merge curried rules with passed by user', ->
+ curried = gtl.curry(or: ['one', 'two'], and: 'three')
+ curried(
+ [{ one: 1, two: 5, three: 4 }, { one: 4, two: 4, three: 9 }, { one: 4, two: -2, three: 3 }, { one: 5, two: 7, three: 1 }]
+ gte: 4
+ ).should.eql [{ one: 1, two: 5, three: 4 }, { one: 4, two: 4, three: 9 }]
+
+ curried = gtl.curry(or: ['one', 'two'], and: 'four')
+ curried(
+ [{ one: 1, two: 5, three: 4 }, { one: 4, two: 4, three: 9 }, { one: 4, two: -2, three: 3 }, { one: 5, two: 7, three: 1 }]
+ gte: 4
+ and: 'three'
+ ).should.eql [{ one: 1, two: 5, three: 4 }, { one: 4, two: 4, three: 9 }]
+
+ it 'should curry iterator', ->
+ curried = gtl.curry(gte: 4, (obj) -> obj.num)
+ curried(
+ [{ num : 1 }, { num : 2 }, { num : 3 }, { num : 4 }, { num : 5 }]
+ ).should.eql [{ num : 4 }, { num : 5 }]
+
+ curried = gtl.curry(gte: 4, (obj) -> obj.bum)
+ curried(
+ [{ num : 1 }, { num : 2 }, { num : 3 }, { num : 4 }, { num : 5 }]
+ (obj) -> obj.num
+ ).should.eql [{ num : 4 }, { num : 5 }]
describe 'gtl.clone', ->
View
33 src/gtl.coffee
@@ -23,6 +23,21 @@ gtl = {}
clone = (array) -> array.slice()
###
+ Internal: merge objects
+###
+merge = (a = {}, b = {}) ->
+ result = {}
+
+ copyPropsToResult = (obj) ->
+ for own key, value of obj
+ result[key] = value
+
+ copyPropsToResult(a)
+ copyPropsToResult(b)
+
+ result
+
+###
Internal: get element by path
###
getByPath = (obj, path) ->
@@ -166,9 +181,21 @@ gtl.rules.fuzzy = (str, searchStr) ->
###
Public: curry function
###
-gtl.curry = (curriedRules) ->
- (array, rules) ->
- gtl.filter(array, curriedRules)
+gtl.curry = (curriedRules, curriedIterator) ->
+ (array, userRules, userIterator = curriedIterator) ->
+ if userRules and userRules.constructor == Function
+ rules = curriedRules
+ iterator = userRules
+ else
+ rules = merge(curriedRules, userRules)
+ iterator = userIterator
+
+ gtl.filter(array, rules, iterator)
+
+###
+ Public: clone gtl object
+###
+gtl.clone = ->
# Export gtl to global scope
if window?

No commit comments for this range

Something went wrong with that request. Please try again.