Skip to content

Instantly share code, notes, and snippets.

@birojow
Last active October 9, 2024 11:28
Show Gist options
  • Save birojow/7c54b4469e77d285700b487364eceed2 to your computer and use it in GitHub Desktop.
Save birojow/7c54b4469e77d285700b487364eceed2 to your computer and use it in GitHub Desktop.

Clojure: (every? #(= % (first cpf)) cpf)

Elixir: String.graphemes(cpf) |> Enum.all?(&(&1 == String.first(cpf)))

F#: cpf |> Seq.forall (fun c -> c = cpf.[0])

Haskell: all (== head cpf) cpf

Java: cpf.chars().allMatch(ch -> ch == cpf.charAt(0));

Kotlin: cpf.all { it == cpf[0] }

Python: all(char == cpf[0] for char in cpf)

Ruby: cpf.chars.all? { |c| c == cpf[0] }

Rust: cpf.chars().all(|c| c == cpf.chars().next().unwrap());

Scala: cpf.forall(_ == cpf.head)

Swift: cpf.allSatisfy { $0 == cpf.first }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment