Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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/4605949ef57f540166ac76f1974cb8e1f890341e
// 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.1.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