Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This This is in Scala will rate thanks! Problem 3 (20 points) A (10 points) We defined lists in the class as an inductive datatype.

image text in transcribedimage text in transcribedThisimage text in transcribedThis is in Scala will rate thanks!

Problem 3 (20 points) A (10 points) We defined lists in the class as an inductive datatype. Let's define a NumOption type for functions with optional return values (such as Some (2) or None ). See note on option types as the inspiration for NumOption: https://www.geeksforgeeks.org/scala-option/ We will use the following grammar: NumOption None denotes the lack of a value | Some(Integer) denotes an integer value First define, the NumOption datatype following the grammar above. Next write a recursive function that returns the nth element of the list. However, if the list size is smaller than n you should return a None signalling no element can be found or otherwise Some(x) where x is the nth element. Also, if n Boolean): NumList that takes in a NumList and a function f: Int => Boolean 1. It should return a new list that consist of all elements of the list 1 that return true when the function f is called on them. 2. The returned list elements must preserve the same order as in the original list. : // YOUR CODE HERE ??? Problem 3 (20 points) A (10 points) We defined lists in the class as an inductive datatype. Let's define a NumOption type for functions with optional return values (such as Some (2) or None ). See note on option types as the inspiration for NumOption: https://www.geeksforgeeks.org/scala-option/ We will use the following grammar: NumOption None denotes the lack of a value | Some(Integer) denotes an integer value First define, the NumOption datatype following the grammar above. Next write a recursive function that returns the nth element of the list. However, if the list size is smaller than n you should return a None signalling no element can be found or otherwise Some(x) where x is the nth element. Also, if n Boolean): NumList that takes in a NumList and a function f: Int => Boolean 1. It should return a new list that consist of all elements of the list 1 that return true when the function f is called on them. 2. The returned list elements must preserve the same order as in the original list. : // YOUR CODE HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions