Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 25, 2024 10:18
Show Gist options
  • Save dacr/40b50823f17d82d78dceb0cda345cfde to your computer and use it in GitHub Desktop.
Save dacr/40b50823f17d82d78dceb0cda345cfde to your computer and use it in GitHub Desktop.
lift/unlift scala feature / published by https://github.com/dacr/code-examples-manager #3d4c01e1-0654-4485-b77d-0b393eee934a/4ee57d58a5e13948b5056c0a25a942fe2dc196d9
// summary : lift/unlift scala feature
// keywords : scala, language-feature, lift, unlift, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 3d4c01e1-0654-4485-b77d-0b393eee934a
// created-on : 2022-06-15T20:39:26+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
// ---------------------
val accesserA = Array(1,2,3).lift
assert(accesserA(1) == Some(2))
val accesserM = Map(1->"a", 2->"b").lift
assert(accesserM(1) == Some("a"))
def f(i:Int)=Some(i)
val ua = Function.unlift(f)
ua(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment