TakeUnless<T> extension

takeUnless returns the current value if the given block is not satisifed, will return null if it is.

takeUnless is a filtering function for a single object.

final number = Random().nextInt(10);
final oddOrNull = number.takeUnless((it) => it % 2 == 0);
print('odd: $oddOrNull');

When chaining other functions after takeUnless, don't forget to use the ?. safe call or perform a null check.

on
  • T?

Methods

takeUnless(bool block(T it)) → T?
Return the current value if the given block is not satisfied, will return null if it is.