The trailing closure is beautiful!

user2345 user2345 at 67.hu
Tue Dec 8 12:12:41 UTC 2020


On Monday, 7 December 2020 at 19:37:43 UTC, zoujiaqing wrote:
> In swift:
>
> ```
> import SwiftUI
>
> struct ContentView: View {
>     var body: some View {
>         Text("Hello World")
>     }
> }
> ```
>
>
> In kotlin:
>
> ```
> @Composable
> fun ArtistCard(artist: Artist) {
>     Row(verticalGravity = Alignment.CenterVertically) {
>         Image(...)
>         Column {
>             Text(artist.name)
>             Text(artist.lastSeenOnline)
>         }
>     }
> }
> ```

I've read a bit the Swift documentation and it seems that it 
works well for them because of how APIs are modeled, i.e optional 
trailing delegate is idomatic in their libraries.

Let's compare to D.
1. lambda are often used as template parameter.
2. non templatized lambda are often lazy, i.e build by the 
compiler from an expression.

   void get(lazy string) { }

   void main(string[] args)
   {
     get() {return "a";}; // would not work, similarly to 
"get({"a"})" that does not.
   }

Not sure if that would work well.


More information about the Digitalmars-d mailing list