ankurp / dollar Goto Github PK
View Code? Open in Web Editor NEWA functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript
Home Page: https://www.dollarswift.org
License: MIT License
A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript
Home Page: https://www.dollarswift.org
License: MIT License
println(",".join($.uniq(["Stockholm", "Stockholm", "SE"])))
Outputs
SE,Stockholm
It should output
Stockholm,SE
You do not need to use $. or make your functions part of a class. I agree in the functional win here, but consider making it special to swift.
Adding following methods for array types. If they are implemented ignore:
compact
difference
drop → rest
findIndex
findLastIndex
first
flatten
head → first
indexOf
initial
intersection
last
lastIndexOf
object → zipObject
pull
range
remove
rest
sortedIndex
tail → rest
take → first
union
uniq
unique → uniq
unzip → zip
without
xor
zip
zipObject
Add ability to lazily evaluated chained methods
I could see adopting a huge amount of useful functions, (like ActiveSupport does for Ruby on Rails), however I don't want to start writing these methods until I know what the scope of features you are wanting to allow.
I.E. in ruby/active_support gem there is a method to_sentence
["Cat", "Dog", "Mouse", "Banana"].to_sentence => "Cat, Dog, Mouse, and Banana"
Just one example but I wanted to find out before I start to contribute as I strongly believe in this project.
@ankurp my project fails to compile because you are referencing a local file in gen_auto_curry.rb.
.../Dollar.swift/Dollar/gen_auto_curry.rb:24:in `initialize': No such file or directory - /Users/ankur/Personal/Dollar.swift/Dollar/Dollar/AutoCurry.swift (Errno::ENOENT)
My observation
Are there plans to support forEach(map without return value) on Array for Dollar and Cent?
Add collection methods:
at
every
find
min
max
pluck
Add auto curry like Wu.js
Just curious if you would consider adding helpers for NSRegularExpression. Apple's regex library is good, but it's a painful API to use and maintain. Otherwise, loving the library you've built!
Shuffle is built into ruby arrays and has frequently been useful for me.
Started work on it at https://github.com/nottombrown/Dollar.swift
Add other types of objects and methods to array class
Add String subscript for bracket syntax to make code below possible
"hello"[0] // "h"
"hello"[0..2] // "hel"
This is a good starting point for implementation:
http://stackoverflow.com/a/24144365/650722
At the moment Code Signing Identity is not set. Would be good to have iOSDeveloper set out of the box. As we have in Dollar. Otherwise great tool!
Call a function after it is called n times.
For Array
extension: As per docs, I would expect
let unFlattened = ["foo", ["bar"], [["spam"]], [[["eggs"]]] ]
let flattened = unFlattened.flatten()
=> ["foo", "bar", "spam", "eggs"]
But instead I obtain
let flattened = unFlattened.flatten()
=> ["foo", {{…}}, {{…}}, __NSArray]
For Dictionary
extension, I would expect:
var dic = ["foo": "bar"]
var another = ["foo": "baz"]
dic.merge(another)
=> ["foo": "baz"]
Instead I get an execution failed.
trace:
playground execution failed: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x9).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
* thread #1: tid = 0x208d2c, 0x000000010a707d39 libswift_stdlib_core.dylib`_swift_retain_(swift::HeapObject*) + 9, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x9)
* frame #0: 0x000000010a707d39 libswift_stdlib_core.dylib`_swift_retain_(swift::HeapObject*) + 9
frame #1: 0x000000010d656672
Xcode is hanging on Compiling source files
when I try to run the test suite on master.
I isolated the issue to the line
XCTAssertEqualObjects(first([1, 2, 3, 4, 5, 6, 7, 8, 9])!, 1, "Return first element")
If the test array has more than 8 elements in it, the compilation always fails.
Could someone please check out the code on my branch and see if the issue can be replicated?
Thanks!
With Xcode beta 4 release the tests are able to run now faster then before and are failing and need to be fixed. Some are due to language changes and some test might be failing due to genuine logic error in some methods.
Hey, this is very most likely my fault and not an issue with Dollar, but I'm trying to get $.find
to work with JSON data [[String:AnyObject]]
I have a function that retrieves the data for me
func Posts() -> [[String:AnyObject]] {...}
Then, I'm trying to filter the posts based on an id:
func Post(postId:String) -> [String:AnyObject] {
return $.find(Posts(), iterator: { $0["_id"] == postId }) as [String:AnyObject]
}
I'm stuck with this error: Type '[String:AnyObject]' does not conform to protocol 'Equatable'
Builds and runs fine within Xcode, but when I try to build using xcodebuild
in Terminal (needed for Facebook approval), my Swift files cannot find Dollar.
This is the command I'm running
xcodebuild -arch i386 -sdk iphonesimulator8.1
This is a representative example of the errors I'm getting:
CompileSwift normal i386 /Users/davidaragon/dev/status/Status/ViewController.swift
cd /Users/davidaragon/dev/status
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/davidaragon/dev/status/Status/Author.swift /Users/davidaragon/dev/status/Status/AlertViewController.swift /Users/davidaragon/dev/status/Status/StatusView.swift /Users/davidaragon/dev/status/Status/NewsFeedItem.swift /Users/davidaragon/dev/status/Status/ProgressBarScoreView.swift -primary-file /Users/davidaragon/dev/status/Status/ViewController.swift /Users/davidaragon/dev/status/Status/AuthorCell.swift /Users/davidaragon/dev/status/Status/FacebookAdapter.swift /Users/davidaragon/dev/status/SwiftRegex.swift /Users/davidaragon/dev/status/Status/AppDelegate.swift /Users/davidaragon/dev/status/Status/LoadingViewController.swift /Users/davidaragon/dev/status/Status/GameViewController.swift /Users/davidaragon/dev/status/Promise.swift -target i386-apple-ios8.1 -target-cpu yonah -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -I /Users/davidaragon/dev/status/build/Release-iphonesimulator -F /Users/davidaragon/dev/status/build/Release-iphonesimulator -F /Users/davidaragon/dev/status -g -import-objc-header /Users/davidaragon/dev/status/Bridging-Header.h -Xcc -I/Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Status-generated-files.hmap -Xcc -I/Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Status-own-target-headers.hmap -Xcc -I/Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Status-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/davidaragon/dev/status/build/Status.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Status-project-headers.hmap -Xcc -I/Users/davidaragon/dev/status/build/Release-iphonesimulator/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/DerivedSources/i386 -Xcc -I/Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/DerivedSources -emit-module-doc-path /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Objects-normal/i386/ViewController~partial.swiftdoc -O -module-name Status -emit-module-path /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Objects-normal/i386/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Objects-normal/i386/ViewController.dia -emit-dependencies-path /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Objects-normal/i386/ViewController.d -o /Users/davidaragon/dev/status/build/Status.build/Release-iphonesimulator/Status.build/Objects-normal/i386/ViewController.o
/Users/davidaragon/dev/status/Status/FacebookAdapter.swift:10:8: error: no such module 'Dollar'
import Dollar
That last line is the crucial bit:
/Users/davidaragon/dev/status/Status/FacebookAdapter.swift:10:8: error: no such module 'Dollar'
import Dollar
The earlier build step to actually compile Dollar seems to be succeeded. It's when I try to import Dollar that xcodebuild breaks.
Line
XCTAssertNil($.find([1, 2, 3, 4], iterator: { $0 == 10 }), "Return nil when object not found")
produces
/Users/lebedzeu/src/git/Dollar.swift/DollarTests/DollarTests.swift:163:9: Could not find an overload for '==' that accepts the supplied arguments
Now Xcode6 Beta4
had been around for a couple of days, the notable change was the Access Control
, you should update source to Beta4
.
Swift compiler is still buggy even in Beta 2 of Xcode. I have am implementation that I will submit when the compiler is improved as it gets stuck in infinite loop and hogs all of the memory along with SourceKit.
Pass index in chained each and map functions
Something like this, anybody work on that?
The current implementation of $.difference
removes duplicate elements from the source array which is unexpected behavior.
We should add the following test and make sure it passes:
XCTAssertEqualObjects($.difference([1, 1], []), [1, 1], "Difference of arrays")
When you shuffle an Array for ex: $.shuffle([1,2,3,4,5,6])
It never returns the first item in first array position and last item in last position too.
You can't return for ex: [1,5,3,4,2,6]
It seems I can't use it for a os x project
Example:
$([[[2], 3], 4]).flatten().first().value()
should return 2
I would love to see a short function for .stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet())
in Cent
$.reverse which works on an array would be useful
Building with XCode 6 Beta 6 fails with the following errors:
Dollar.swift:297:29: Cannot create a variadic tuple
Dollar.swift:297:16: '(T...)' is not a subtype of 'T'
Dollar.swift:312:47: Cannot create a variadic tuple
Dollar.swift:349:33: Cannot create a variadic tuple
Dollar.swift:873:33: Cannot create a variadic tuple
I've already started my work on a fix. Stay tuned.
Is it possible to use these packages in a Playground?
I still can't figure out how to get this to work in my project. Do I drag the .xcodeproj into my .xcworkspace? Do I drag just the folder? Or the .framework? Sorry, I'm just not to familiar with not using Cocoapods ;)
Some tests are commented as they are failing due to not properly checking equality. Uncomment and try to get the test working of if its the code that is broken then fix the code.
Add test project using library for iOS and Mac
Need to finish implementing some of the methods with TODO
I think one of the things that Underscore got wrong was having the collection be the first parameter. Why? Currying a function becomes way less useful. If the collection was the last parameter, you could create curried functions that preload your logic, and all you need to do is pass it the data.
Thoughts?
Add times method like in lodash that returns values that can be mapped or does not return but just calls a method n times
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.