GithubHelp home page GithubHelp logo

florent37 / missing_kotlin Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 3.0 12 KB

"Flutter is **** because it does not use Kotlin" Already heard it ? Prove them you can do the same thing as Kotlin using Flutter/Dart !

Home Page: https://pub.dev/packages/missing_kotlin

License: Other

Dart 99.63% Shell 0.37%
flutter dart kotlin when if also let run takeif takeunless

missing_kotlin's Introduction

missing_kotlin

"Flutter is **** because it does not use Kotlin" Already heard it ? Prove them you can do the same thing as Kotlin using Flutter/Dart !

.let

Work like .let in kotlin

final calculated = myMethod()?.let((v){
  return v*2;
}) ?? 0;

Will also break th chain if th expression is null

String variable; //null
final calculated = variable?.let((v) => v.length());

//here the expression is null, it will not execute the lambda
expect(calculated, null);

.also

Work like .also in kotlin

final result = myMethod()?.also((v){
  print(v);
});

result here is the return value of myMethod()

.run

Work like .run in kotlin

final calculated = myMethod()?.let((v){
  return v*2;
}) ?? run(() => 3);

.takeIf

Work like .takeIf in kotlin

final calculated = myMethod()?.takeIf((v) => v == 3)?.let((v){
  return v*2;
}) ?? 0;

When

final variable = 3;
final result = when(variable, [
    Case(2, () => "A"),
    Case(3, () => "B"),
    Default(() => "C"),
]);

//here the result is "B"
expect(calculated, null);

If

Like a Kotlin if, returning a value, but with an Uppercase (because if is a reserved word)

final result = If(1 == 2, 
  () => "A", 
  Else: () => "B"
);

//here the result is "B"
expect(result, "1");

You can also chain statements

final variable2 = 1;
final result = If(variable2 == 2,
    () => "A",
  Else: () => 
    If(variable2 == 3,
        () => "B",
    Else: 
        () => "C"
  ),
);

//here the result is "C"
expect(result, "C");

missing_kotlin's People

Contributors

florent37 avatar hpoul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.