Last active
August 19, 2022 11:36
-
-
Save VintageAppMaker/a542cb51beaf3c1b822192bd09cf4d0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 참조: https://stackoverflow.com/questions/52148319/what-is-darts-equivalent-to-kotlins-let | |
void main() { | |
Map? item = null; | |
// 1.Map 테스트 | |
item = {"name" : "snake"}; | |
var tmp1 = item?.let((t){return t["name"];}); | |
print ("${tmp1}"); | |
item.apply((t){ | |
t.remove("name"); | |
t["age"] = 100; | |
}); | |
print ("name => ${item['name']} age => ${item['age']}"); | |
item = null; | |
var tmp2 = item?.let((t){return t["name"];}); | |
print ("${tmp2}"); | |
// 2. int 테스트 | |
int? count = 0; | |
var bEven = count?.let ((t){ return t.isEven;}); | |
print ("${bEven}"); | |
int? count2 = null; | |
var bEven2 = count2?.let ((t){ return t.isEven;}); | |
print ("${bEven2}"); | |
// 3. Data 테스트 | |
Data d = Data().apply((t){ | |
t.name = "test"; | |
return t; | |
}); | |
print ("${d.name}"); | |
} | |
class Data{ | |
late String name; | |
} | |
extension ObjectExt<T> on T { | |
R let<R>(R Function(T that) fn) => fn(this); | |
// let으로도 apply 기능이 되지만, kotlin과 유사하게 만들었음. | |
apply<R>(R Function(T that) fn) => fn(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment